-
Notifications
You must be signed in to change notification settings - Fork 3
/
henon_attractor.py
61 lines (43 loc) · 1.01 KB
/
henon_attractor.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
# henon_attractor.py
# A program to display the Henon map.
# import third-party libraries
import numpy as np
import matplotlib.pyplot as plt
def henon_attractor(x, y, a=1.4, b=0.3):
'''Computes the next step in the Henon map
Args:
x: float, current x value
y: float, current y value
kwargs:
a, b: float, constants
Returns:
x_next: float, current x value
y_next: flaot, current y value
'''
x_next = 1 - a * x ** 2 + y
y_next = b * x
return x_next, y_next
def map_henon(steps):
"""
Produce the Henon map
Args:
steps: int, number of iterations
Returns:
None
"""
x_arr, y_arr = [], []
# starting point
x_arr.append(0.3), y_arr.append(0.3)
for i in range(steps):
x_next, y_next = henon_attractor(x_arr[-1], y_arr[-1])
x_arr.append(x_next)
y_arr.append(y_next)
# display plot
plt.style.use('dark_background')
plt.plot(x_arr, y_arr, '^', color='white', alpha = 0.4, markersize=0.1)
plt.axis('off')
plt.show()
plt.close()
# number of iterations
steps = 1000000
map_henon(steps)