This repository was archived by the owner on Jun 17, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
133 lines (101 loc) · 3.21 KB
/
Copy pathmain.py
File metadata and controls
133 lines (101 loc) · 3.21 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import numpy as np
import matplotlib
matplotlib.use('TKAgg')
from matplotlib import pyplot as plt
from core.map_base import MapBase
class Logistic(MapBase):
def __init__(self, r, x0, **kwargs):
super(Logistic, self).__init__(**kwargs)
self.name = "Logistic"
self.params = {
"r": r
}
self.vars = {
"x_n": x0
}
def iterate(self, x_n=None):
if x_n is not None:
return self.params["r"] * x_n * (1.0 - x_n),
else:
raise ValueError("Iteration variable can't be None!")
class Gauss(MapBase):
def __init__(self, alpha, beta, x0, **kwargs):
super(Gauss, self).__init__(**kwargs)
self.name = "Gauss"
alpha, beta = np.meshgrid(alpha, beta)
self.params = {
"alpha": alpha,
"beta": beta
}
self.vars = {
"x_n": x0
}
def iterate(self, x_n=None):
if x_n is not None:
return np.exp(-self.params["alpha"] * np.square(x_n)) + self.params["beta"],
else:
raise ValueError("Iteration variable can't be None!")
class Henon(MapBase):
def __init__(self, a, b, x0, y0, **kwargs):
super(Henon, self).__init__(**kwargs)
self.name = "Henon"
a, b = np.meshgrid(a, b)
self.params = {
"a": a,
"b": b
}
self.vars = {
"x_n": x0,
"y_n": y0
}
def iterate(self, x_n=None, y_n=None):
if x_n is not None and y_n is not None:
return y_n + 1 - self.params["a"] * np.square(x_n), self.params["b"] * x_n
else:
raise ValueError("Iteration variables can't be None!")
class Duffing(MapBase):
def __init__(self, a, b, x0, y0, **kwargs):
super(Duffing, self).__init__(**kwargs)
self.name = "Duffing"
a, b = np.meshgrid(a, b)
self.params = {
"a": a,
"b": b
}
self.vars = {
"x_n": x0,
"y_n": y0
}
def iterate(self, x_n=None, y_n=None):
if x_n is not None and y_n is not None:
return y_n, -self.params["b"] * x_n + self.params["a"] * y_n - np.square(y_n)
else:
raise ValueError("Iteration variables can't be None!")
if __name__ == "__main__":
print("*** Bifurcation diagrams ***")
n = 1000
iterations = 1000
# r = np.linspace(2.7, 4, n)
# x0 = 1e-5 * np.ones([n])
# logistic = Logistic(r, x0, last_num=200)
# logistic.plot_bifurcation_diagram(iterations)
alpha = np.linspace(3.0, 12.0, n)
beta = np.linspace(-1.0, 1.0, n)
x0 = 1e-5 * np.ones([n, n])
gauss = Gauss(alpha, beta, x0)
gauss.plot_bifurcation_diagram(iterations)
#
# a = np.linspace(1, 1.4, n)
# b = np.linspace(0.29, 0.31, n)
# x0 = 1e-5 * np.ones([n, n])
# y0 = 1e-5 * np.ones([n, n])
# henon = Henon(a, b, x0, y0)
# henon.plot_bifurcation_diagram(iterations)
#
# a = np.linspace(2.5, 3.8, n)
# b = np.linspace(0, 0.5, n)
# x0 = 1e-5 * np.ones([n, n])
# y0 = 1e-5 * np.ones([n, n])
# duffing = Duffing(a, b, x0, y0)
# duffing.plot_bifurcation_diagram(iterations)
plt.show()