-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhenon_map.py
43 lines (35 loc) · 892 Bytes
/
henon_map.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
import numpy as np
import matplotlib.pyplot as plt
# This program plots and saves the long-term behaviour
# of the Henon map.
# Parameters
a = 1.4
b = 0.3
# Sample Sizes
ntransient = 0
nsamples = 10**5
def henon(v):
x, y = v
return np.array([y + 1 - a*x**2, b*x])
def run(pos0, ntransient, nsamples):
pos = pos0
samples = np.zeros((nsamples, 2))
for i in range(ntransient):
pos = henon(pos)
for i in range(nsamples):
pos = henon(pos)
samples[i] = pos
return samples
def grapher(samples):
x, y = samples.T
plt.scatter(x, y, s=0.75)
plt.xlabel("x")
plt.ylabel("y")
plt.title(f"Henon map for a = {a} and b = {b}")
if __name__ == "__main__":
pos0 = np.array([0, 0])
samples = run(pos0, ntransient, nsamples)
grapher(samples)
print(samples.shape)
plt.savefig("plots/henon_map.png")
plt.show()