Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/local/bin/python
- # import the matplotlib modules and set the output to PDF
- import matplotlib
- matplotlib.use("PDF")
- import matplotlib.pyplot as plt
- from compPhys import *
- h = 0.01
- G = 0.1
- # Plotting
- plt.subplot(211)
- plt.plot(Euler(h,G)[2], Euler(h,G)[0], 'r-', label=r'$Euler$')
- plt.plot(LeapFrog(h,G)[2], LeapFrog(h,G)[0], 'g-', label=r'$Leapfrog$')
- plt.plot(RK4(h,G)[2], RK4(h,G)[0], 'b-', label=r'$RK4$')
- plt.ylabel(r"$\theta$ (radians)")
- plt.grid()
- plt.subplot(212)
- plt.plot(Euler(h,G)[2], Euler(h,G)[1], 'r-', label='Euler')
- plt.plot(LeapFrog(h,G)[2], LeapFrog(h,G)[1], 'g-', label='Leapfrog')
- plt.plot(RK4(h,G)[2], RK4(h,G)[1], 'b-', label='RK4')
- plt.ylabel('Total Energy (J)')
- plt.xlabel("Time (s)")
- plt.grid()
- plt.savefig("Plots/singlePendulum")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement