Simple logistic map using python and matplotlib.
import math
import matplotlib.pyplot as plt
def logistic(xa =2.9 , xb=4.0 , imgx = 240 , imgy = 500,
maxit = 200, f=lambda x,r: r * x * (1 - x) ):
xs = []
ys = []
for i in range(imgx):
r = xa + (xb - xa) * float(i)/(imgx - 1)
x = 0.5
for j in range(maxit):
x = f(x,r)
if j > maxit / 2:
xs.append( i )
ys.append(int(x * imgy))
return [xs,ys]
myfunction = lambda x,r: r * (math.sin(x)**2)
points = logistic( xa = 2.1 ,xb = 3.1, imgy=200 , f=myfunction)
ax = plt.subplot(121)
ax.scatter(points[0], points[1], s= 1)
points = logistic()
bx = plt.subplot(122)
bx.scatter(points[0], points[1], s= 1)
plt.show()

Nessun commento:
Posta un commento