Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. # plot periodic orbits and iterations for the logistic map
  2. #
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6.  
  7. # logistic map is f(x) = mu*x*(1-x) with mu in (0,4)
  8. def logistic(x, mu):
  9. y = mu * x * (1.0 - x)
  10. return y
  11.  
  12.  
  13. # fill an array with iteration n1 to n2 of the logistic map starting with x0
  14. # and with parameter mu
  15. def fillit(n1, n2, x0, mu):
  16. x = x0 # initial x value
  17. z = np.linspace(0.0, 1.0, n2 - n1) # create an array
  18. for i in range(0, n1): # do n1 iterations
  19. x = logistic(x, mu)
  20.  
  21. for i in range(0, n2 - n1): # fill n2-n1 iterations
  22. x = logistic(x, mu)
  23. z[i] = x
  24.  
  25. return z # returning the array
  26.  
  27.  
  28. # plot the iterated logistic map for nmu number of mu values
  29. def mkplot(mu_min, nmu): # nmu is number of mu values to use, mu_min range
  30. mu_max = 4.0 # maximum mu value
  31. muarr = np.linspace(mu_min, mu_max, nmu)
  32. n1 = 100 # specify iteration range
  33. n2 = 200
  34. x0 = 0.4 # initial x
  35. for i in range(0, nmu):
  36. mu = muarr[i]
  37. y = fillit(n1, n2, x0, mu) # get the array of iterations
  38. x = y * 0.0 + mu # dummy x value is all mu
  39. plt.plot(x, y, 'ko', markersize=1) # k=black, plot small points
  40.  
  41.  
  42. plt.figure()
  43. plt.xlabel(r'$\mu$', fontsize=20)
  44. mu_min = 2.9
  45. plt.axis([mu_min, 4.0, 0, 1.0])
  46. # this makes the plot!
  47. mkplot(mu_min, 1000)
  48. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement