Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.integrate import odeint
  4.  
  5.  
  6. def solveit(n,y0):
  7. def exam(y, x):
  8. theta, omega = y
  9. dydx = [omega, - (2.0/x)*omega - theta**n]
  10. return dydx
  11.  
  12. x = np.linspace(0.1, 10, 100)
  13.  
  14. #call integrator
  15. sol = odeint(exam, y0, x)
  16.  
  17. plt.plot(x, sol[:, 0], label='For n = %s,y0=(%s,%s)'%(n,y0[0],y0[1]))
  18.  
  19.  
  20. ys= [[1.0, 0.0],[1.2, 0.2],[1.3, 0.3]]
  21.  
  22. fig = plt.figure()
  23. for y_ in ys:
  24. solveit(1.,y_)
  25.  
  26. plt.legend(loc='best')
  27. plt.grid()
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement