Added script
This commit is contained in:
33
logistic_map.py
Normal file
33
logistic_map.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from itertools import islice
|
||||||
|
|
||||||
|
|
||||||
|
class LogisticMap(object):
|
||||||
|
def __init__(self, r, x0):
|
||||||
|
self.r = r
|
||||||
|
self.x0 = x0
|
||||||
|
|
||||||
|
def compute(self, x):
|
||||||
|
return self.r * x * (1 - x)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
x = self.x0
|
||||||
|
yield np.broadcast_to(x, np.shape(self.r))
|
||||||
|
for _ in range(n_iter):
|
||||||
|
x = self.compute(x)
|
||||||
|
yield x
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
return islice(self, *args)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
r_list = np.linspace(2, 4, 501)
|
||||||
|
n_iter = 1001
|
||||||
|
seed = 0.5
|
||||||
|
|
||||||
|
x_final = list(zip(*LogisticMap(r_list, seed)(100, 1001)))
|
||||||
|
|
||||||
|
plt.plot(r_list, x_final)
|
||||||
|
plt.show()
|
||||||
Reference in New Issue
Block a user