Advertisement
Sephinroth

153556

Apr 9th, 2021
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. Q = 200
  5. P = np.zeros(Q)
  6. P[0] = 1
  7. PP = np.zeros(Q)
  8. t_max = 100
  9. dt = 0.001
  10. lmbd = 4
  11. mu = 5
  12. t = 0
  13. p0 = [1]
  14. p1 = [0]
  15.  
  16. while t < t_max:
  17.     PP[0] = dt * (-lmbd * P[0] + mu * P[1])
  18.     for j in range(1, Q-1):
  19.         PP[j] = dt * (-(lmbd + mu) * P[j] + lmbd * P[j-1] + mu * P[j + 1])
  20.     for j in range(Q):
  21.         P[j] += PP[j]
  22.         t += dt
  23.     p0.append(P[0])
  24.     p1.append(P[1])
  25. print(P, p0, p1, sep='\n')
  26. t_to_plot = np.linspace(0, 100, 200)
  27. p0 = p0[:200]
  28. p1 = p1[:200]
  29. #plt.plot(t_to_plot, P)
  30. plt.plot(t_to_plot, p0)
  31. plt.plot(t_to_plot, p1)
  32. plt.show()
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement