All checks were successful
continuous-integration/drone/push Build is passing
35 lines
704 B
Python
35 lines
704 B
Python
from itertools import islice
|
|
|
|
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
|
|
|
|
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()
|