-
Notifications
You must be signed in to change notification settings - Fork 1
/
lorenz_change_params_multiplot.py
86 lines (67 loc) · 2.63 KB
/
lorenz_change_params_multiplot.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
# Vykreslení Lorenzova atraktoru s různými parametry s a r
# MIT License
#
# Copyright (c) 2024 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.
import matplotlib.pyplot as plt
import numpy as np
def lorenz(x, y, z, s=10, r=28, b=2.667):
"""Výpočet dalšího bodu Lorenzova atraktoru."""
x_dot = s * (y - x)
y_dot = r * x - y - x * z
z_dot = x * y - b * z
return x_dot, y_dot, z_dot
# krok (změna času)
dt = 0.01
# celkový počet vypočtených bodů na Lorenzově atraktoru
n = 1000
def draw_lorenz_for_input_values(ax, dt, n, x0, y0, z0, s, r, b):
# 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] = (x0, y0, z0)
# vlastní výpočet atraktoru
for i in range(n - 1):
x_dot, y_dot, z_dot = lorenz(x[i], y[i], z[i], s, r, b)
x[i + 1] = x[i] + x_dot * dt
y[i + 1] = y[i] + y_dot * dt
z[i + 1] = z[i] + z_dot * dt
# vykreslení grafu
ax.plot(y.copy(), z.copy())
# konstrukce 2D grafu
fig = plt.figure(figsize=(8, 6))
b = 2.667
# vykreslení Lorenzova atraktoru s různými parametry s a r
for si in range(5):
for ri in range(5):
ax = fig.add_subplot(5, 5, si + 1 + ri * 5)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
draw_lorenz_for_input_values(
ax, dt, n, 0.0, 1.0, 1.05, si * 2.0 + 1.0, 4.0 + ri * 4, b
)
# změna velikosti komponent v grafu.
plt.tight_layout()
# uložení grafu
plt.savefig("variable_s_r_params_multiplot.png")
# zobrazení grafu
plt.show()