forked from hsayama/PyCX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds-Lorenz-equations.py
57 lines (47 loc) · 1 KB
/
ds-Lorenz-equations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
s = 10.
r = 30.
b = 3.
Dt = 0.01
def initialize():
global x, xresult, y, yresult, z, zresult, t, timesteps
x = y = z = 1.
xresult = [x]
yresult = [y]
zresult = [z]
t = 0.
timesteps = [t]
def observe():
global x, xresult, y, yresult, z, zresult, t, timesteps
xresult.append(x)
yresult.append(y)
zresult.append(z)
timesteps.append(t)
def update():
global x, xresult, y, yresult, z, zresult, t, timesteps
nextx = x + (s * (y - x)) * Dt
nexty = y + (r * x - y - x * z) * Dt
nextz = z + (x * y - b * z) * Dt
x, y, z = nextx, nexty, nextz
t = t + Dt
initialize()
while t < 30.:
update()
observe()
subplot(3, 1, 1)
plot(timesteps, xresult)
xlabel('t')
ylabel('x')
subplot(3, 1, 2)
plot(timesteps, yresult)
xlabel('t')
ylabel('y')
subplot(3, 1, 3)
plot(timesteps, zresult)
xlabel('t')
ylabel('z')
figure()
ax = gca(projection='3d')
ax.plot(xresult, yresult, zresult, 'b')
show()