-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lorenz-mod-2.py
118 lines (94 loc) · 3.16 KB
/
Lorenz-mod-2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Výpočet a vykreslení upraveného Lorenzova podivného atraktoru."""
# MIT License
#
# Copyright (c) 2020 Pavel Tišnovský
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Lorenz attractor
# import všech potřebných knihoven - Numpy a Matplotlibu
import matplotlib.pyplot as plt
import numpy as np
def lorenz_mod2(x, y, z, alfa, beta, gamma, delta):
"""Výpočet dalšího bodu Lorenzove mod2 atraktoru."""
x_dot = -alfa * x + y * y - z * z + alfa * gamma
y_dot = x * (y - beta * z) + delta
z_dot = -z + x * (beta * y + z)
return x_dot, y_dot, z_dot
# krok (změna času)
dt = 0.001
# celkový počet vypočtených bodů na Lorenzově atraktoru
n = 100000
# prozatím prázdné pole připravené pro výpočet
x = np.zeros((n,))
y = np.zeros((n,))
z = np.zeros((n,))
# počáteční hodnoty
x[0], y[0], z[0] = (0.1, 0.1, 0)
# vlastní výpočet atraktoru
for i in range(n - 1):
x_dot, y_dot, z_dot = lorenz_mod2(x[i], y[i], z[i], 0.9, 5.0, 9.9, 1.0)
x[i + 1] = x[i] + x_dot * dt
y[i + 1] = y[i] + y_dot * dt
z[i + 1] = z[i] + z_dot * dt
# konstrukce 3D grafu
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(projection="3d")
# změna velikosti komponent v grafu.
plt.tight_layout()
# vykreslení grafu
ax.plot(x[50000:], y[50000:], z[50000:])
# uložení grafu
plt.savefig("lorenz_mod_1.png")
# zobrazení grafu
plt.show()
# grafy s více pohledy na atraktor
ch_3d = np.stack((x, y, z))
lim_xyz = [(np.min(ch_3d[ii]), np.max(ch_3d[ii])) for ii in range(3)]
fig2 = plt.figure("3D Coordinates", figsize=(8, 6))
plt.subplot(2, 2, 1)
plt.plot(y, x, linewidth=0.75)
plt.grid()
plt.xlabel("X")
plt.ylabel("Y")
plt.xlim(lim_xyz[1])
plt.ylim(lim_xyz[0])
plt.subplot(2, 2, 2)
plt.plot(y, z, linewidth=0.75)
plt.grid()
plt.xlabel("Z")
plt.ylabel("Y")
plt.xlim(lim_xyz[1])
plt.ylim(lim_xyz[2])
plt.subplot(2, 2, 3)
plt.plot(z, x, linewidth=0.75)
plt.grid()
plt.xlabel("X")
plt.ylabel("Z")
plt.xlim(lim_xyz[2])
plt.ylim(lim_xyz[0])
ax = fig2.add_subplot(2, 2, 4, projection="3d")
ax.plot(x, y, z, linewidth=0.7)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.tight_layout()
# uložení grafu
plt.savefig("lorenz_mod_2.png")
# zobrazení grafu
plt.show()