1 | r""" |
---|
2 | sage: import scipy; from scipy import integrate |
---|
3 | sage: f = lambda y, t: - cos(y * t) |
---|
4 | sage: t = srange(0, 5, 0.1); p = Graphics() |
---|
5 | sage: for k in srange(0, 10, 0.15): |
---|
6 | ... y = integrate.odeint(f, k, t) |
---|
7 | ... p += line(zip(t, flatten(y))) |
---|
8 | sage: t = srange(0, -5, -0.1); q = Graphics() |
---|
9 | sage: for k in srange(0, 10, 0.15): |
---|
10 | ... y = integrate.odeint(f, k, t) |
---|
11 | ... q += line(zip(t, flatten(y))) |
---|
12 | sage: y = var('y') |
---|
13 | sage: v = plot_vector_field((1, -cos(x * y)), (x,-5,5), (y,-2,11)) |
---|
14 | sage: g = p + q + v; # g.show() |
---|
15 | """ |
---|
16 | |
---|
17 | r""" |
---|
18 | sage: import scipy; from scipy import integrate |
---|
19 | sage: a, b, c, d = 1., 0.1, 1.5, 0.75 |
---|
20 | sage: def dX_dt(X, t=0): |
---|
21 | ... return [ a*X[0] - b*X[0]*X[1] , |
---|
22 | ... -c*X[1] + d*b*X[0]*X[1] ] |
---|
23 | sage: t = srange(0, 15, .01) # echelle de temps |
---|
24 | sage: X0 = [10, 5] # conditions initiales : 10 lapins et 5 renards |
---|
25 | sage: X = integrate.odeint(dX_dt, X0, t) # resolution numerique |
---|
26 | sage: lapins, renards = X.T # raccourcis de X.transpose() |
---|
27 | sage: p = line(zip(t, lapins), color='red') # trace du nb de lapins |
---|
28 | sage: p += text("Lapins",(12,37), fontsize=10, color='red') |
---|
29 | sage: p += line(zip(t, renards), color='blue')# idem pr les renards |
---|
30 | sage: p += text("Renards",(12,7), fontsize=10, color='blue') |
---|
31 | sage: p.axes_labels(["temps", "population"]); # p.show(gridlines=True) |
---|
32 | sage: ### Deuxieme graphique : |
---|
33 | sage: n = 11; L = srange(6, 18, 12 / n); R=srange(3, 9, 6 / n) |
---|
34 | sage: CI = zip(L, R) # liste des conditions initiales |
---|
35 | sage: def g(x,y): |
---|
36 | ... v = vector(dX_dt([x, y])) # pour un trace plus lisible, |
---|
37 | ... return v/v.norm() # on norme le champ de vecteurs |
---|
38 | sage: x, y = var('x, y') |
---|
39 | sage: q = plot_vector_field(g(x, y), (x, 0, 60), (y, 0, 36)) |
---|
40 | sage: for j in range(n): |
---|
41 | ... X = integrate.odeint(dX_dt, CI[j], t) # resolution |
---|
42 | ... q += line(X, color=hue(.8-float(j)/(1.8*n))) # graphique |
---|
43 | sage: q.axes_labels(["lapins","renards"]); # q.show() |
---|
44 | """ |
---|
45 | |
---|
46 | r""" |
---|
47 | sage: x, y, t = var('x, y, t') |
---|
48 | sage: alpha(t) = 1; beta(t) = t/2; gamma(t) = t + t**3/8 |
---|
49 | sage: env = solve([alpha(t)*x+beta(t)*y==gamma(t),\ |
---|
50 | ... diff(alpha(t),t)*x+diff(beta(t),t)*y==diff(gamma(t),t)],\ |
---|
51 | ... [x,y]) |
---|
52 | sage: f = lambda x:x^2 / 4 |
---|
53 | sage: p = plot(f, -8, 8, rgbcolor=(0.2,0.2,0.4)) # trace la parabole |
---|
54 | sage: for u in srange(0, 8, 0.1): # trace des normales a la parabole |
---|
55 | ... p += line([[u, f(u)], [-8*u, f(u) + 18]], thickness=.3) |
---|
56 | ... p += line([[-u, f(u)], [8*u, f(u) + 18]], thickness=.3) |
---|
57 | sage: p += parametric_plot((env[0][0].rhs(),env[0][1].rhs()),\ |
---|
58 | ... (t, -8, 8),color='red') # trace la developpee |
---|
59 | sage: # p.show(xmin=-8, xmax=8, ymin=-1, ymax=12, aspect_ratio=1) |
---|
60 | sage: t = var('t'); p = 2 |
---|
61 | sage: x(t) = t; y(t) = t^2 / (2 * p) |
---|
62 | sage: f(t) = [x(t), y(t)] |
---|
63 | sage: df(t) = [x(t).diff(t), y(t).diff(t)] |
---|
64 | sage: d2f(t) = [x(t).diff(t, 2), y(t).diff(t, 2)] |
---|
65 | sage: T(t) = [df(t)[0] / df(t).norm(), df[1](t) / df(t).norm()] |
---|
66 | sage: N(t) = [-df(t)[1] / df(t).norm(), df[0](t) / df(t).norm()] |
---|
67 | sage: R(t) = (df(t).norm())^3 / \ |
---|
68 | ... (df(t)[0] * d2f(t)[1] -df(t)[1] * d2f(t)[0]) |
---|
69 | sage: Omega(t) = [f(t)[0] + R(t)*N(t)[0], f(t)[1] + R(t)*N(t)[1]] |
---|
70 | sage: g = parametric_plot(f(t), (t, -8, 8), color='green', thickness=2) |
---|
71 | sage: for u in srange(.4, 4, .2): |
---|
72 | ... g += line([f(t = u), Omega(t = u)], color='red', alpha = .5) |
---|
73 | ... g += circle(Omega(t = u), R(t = u), color='blue') |
---|
74 | sage: # g.show(aspect_ratio=1, xmin=-12, xmax=7, ymin=-3, ymax=12) |
---|
75 | """ |
---|
76 | |
---|
77 | r""" |
---|
78 | sage: u, v = var('u, v') |
---|
79 | sage: h = lambda u,v: u^2 + 2*v^2 |
---|
80 | sage: f = plot3d(h, (u,-1,1), (v,-1,1), aspect_ratio=[1,1,1]) |
---|
81 | sage: f(x, y) = x^2 * y / (x^4 + y^2) |
---|
82 | sage: t, theta = var('t theta') |
---|
83 | sage: limit(f(t * cos(theta), t * sin(theta)) / t, t=0) |
---|
84 | cos(theta)^2/sin(theta) |
---|
85 | sage: solve(f(x,y) == 1/2, y) |
---|
86 | [y == x^2] |
---|
87 | sage: a = var('a'); h = f(x, a*x^2).simplify_rational(); h |
---|
88 | a/(a^2 + 1) |
---|
89 | sage: g = plot(h, a, -4, 4) |
---|
90 | sage: p = plot3d(f(x, y), (x,-2,2), (y,-2,2), plot_points=[150,150]) |
---|
91 | sage: for i in range(1,4): |
---|
92 | ... p += plot3d(-0.5 + i / 4, (x, -2, 2), (y, -2, 2),\ |
---|
93 | ... color=hue(i / 10), opacity=.1) |
---|
94 | """ |
---|
95 | |
---|
96 | r""" |
---|
97 | sage: x, y, z = var('x, y, z'); a = 1 |
---|
98 | sage: h = lambda x, y, z:(a^2 + x^2 + y^2)^2 - 4*a^2*x^2-z^4 |
---|
99 | sage: f = implicit_plot3d(h, (x, -3, 3), (y, -3, 3), (z, -2, 2),\ |
---|
100 | ... plot_points=100, adaptative=True) |
---|
101 | sage: g1 = line3d([(-10*cos(t)-2*cos(5*t)+15*sin(2*t),\ |
---|
102 | ... -15*cos(2*t)+10*sin(t)-2*sin(5*t),\ |
---|
103 | ... 10*cos(3*t)) for t in srange(0,6.4,.1)],radius=.5) |
---|
104 | |
---|
105 | """ |
---|