Files
logistic_map/logistic_map.py
Jan-Niclas Walther 6f0f22fe89
Some checks failed
continuous-integration/drone/push Build is failing
Fix formatting
2020-07-08 21:16:40 +02:00

35 lines
699 B
Python

from itertools import islice
import matplotlib.pyplot as plt
import numpy as np
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()