Ticket #10983: graphique_2.py

File graphique_2.py, 1.8 KB (added by casamayou, 5 years ago)

updated file

Line 
1r"""
2
3sage: g = bar_chart([randrange(15) for i in range(20)], color='red')
4sage: g = bar_chart([x^2 for x in range(1,20)], width=0.2)
5sage: liste = [10 + floor(10*sin(i)) for i in range(100)]
6sage: g = bar_chart(liste)
7sage: g = finance.TimeSeries(liste).plot_histogram(bins=20)
8
9"""
10
11
12r"""
13
14sage: from random import *
15sage: n, l, x, y = 10000, 1, 0, 0; p = [[0, 0]]
16sage: for k in range(n):
17...    theta = (2 * pi * random()).n(digits=5)
18...    x, y = x + l * cos(theta), y + l * sin(theta)
19...    p.append([x, y])
20sage: g1 = line([p[n], [0, 0]], color='red', thickness=2)
21sage: g1 += line(p, thickness=.4); # g1.show(aspect_ratio=1)
22
23"""
24
25
26r"""
27
28sage: length = 200; n = var('n')
29sage: u(n) = n * sqrt(2)
30sage: z(n) = exp(2 * I * pi * u(n))
31sage: vertices = [CC(0, 0)]
32sage: for n in range(1, length):
33...    vertices.append(vertices[n - 1] + CC(z(n)))
34sage: g = line(vertices); # g.show(aspect_ratio=1)
35
36"""
37
38
39r"""
40
41sage: x = var('x'); y = function('y',x)
42sage: DE = x*diff(y, x) == 2*y + x^3
43sage: desolve(DE, [y,x])
44(c + x)*x^2
45sage: sol = []
46sage: for i in srange(-2, 2, 0.2):
47...    sol.append(desolve(DE, [y, x], ics=[1, i]))
48...    sol.append(desolve(DE, [y, x], ics=[-1, i]))
49sage: g = plot(sol, x, -2, 2)
50sage: y = var('y')
51sage: g += plot_vector_field((x, 2*y+x^3), (x, -2, 2), (y, -1, 1))
52sage: # g.show(ymin=-1, ymax=1)
53
54"""
55
56
57r"""
58
59sage: x = var('x'); y = function('y',x)
60sage: DE = x*diff(y, x) == 2*y + x^3
61sage: g = Graphics()
62sage: for i in srange(-1, 1, 0.1):
63...       g += line(desolve_rk4(DE, y, ics=[1, i],\
64...                         step=0.05, end_points=[0,2]))
65...       g += line(desolve_rk4(DE, y, ics=[-1, i],\
66...                         step=0.05, end_points=[-2,0]))
67sage: y = var('y')
68sage: g = plot_vector_field((x, 2*y + x^3), (x,-2,2), (y,-1,1))
69sage: # g.show(ymin=-1, ymax=1)
70
71"""
72