Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/opt/local/bin/python
  2.  
  3. # import the matplotlib modules and set the output to PDF
  4. import matplotlib
  5. matplotlib.use("PDF")
  6. import matplotlib.pyplot as plt
  7.  
  8. from compPhys import *
  9.  
  10. h = 0.01
  11. G = 0.1
  12.  
  13. # Plotting
  14. plt.subplot(211)
  15. plt.plot(Euler(h,G)[2], Euler(h,G)[0], 'r-', label=r'$Euler$')
  16. plt.plot(LeapFrog(h,G)[2], LeapFrog(h,G)[0], 'g-', label=r'$Leapfrog$')
  17. plt.plot(RK4(h,G)[2], RK4(h,G)[0], 'b-', label=r'$RK4$')
  18. plt.ylabel(r"$\theta$ (radians)")
  19. plt.grid()
  20.  
  21. plt.subplot(212)
  22. plt.plot(Euler(h,G)[2], Euler(h,G)[1], 'r-', label='Euler')
  23. plt.plot(LeapFrog(h,G)[2], LeapFrog(h,G)[1], 'g-', label='Leapfrog')
  24. plt.plot(RK4(h,G)[2], RK4(h,G)[1], 'b-', label='RK4')
  25. plt.ylabel('Total Energy (J)')
  26. plt.xlabel("Time (s)")
  27. plt.grid()
  28.  
  29. plt.savefig("Plots/singlePendulum")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement