commit 4de501fbf84e40113024ab3a656db5ad8415dcef Author: Jan-Niclas Walther Date: Wed Feb 12 23:57:24 2020 +0100 Added script diff --git a/logistic_map.py b/logistic_map.py new file mode 100644 index 0000000..48ef9d5 --- /dev/null +++ b/logistic_map.py @@ -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()