Created
July 7, 2012 10:45
-
-
Save iscadar/3065817 to your computer and use it in GitHub Desktop.
A pendulum simulation using Euler integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.integrate import * | |
from scipy import * | |
from matplotlib.pyplot import * | |
##A pendulum simulation | |
##v0.2 | |
##Alexandros Kourkoulas Chondrorizos | |
th=pi/4#((rand()*2)-1)*pi #initial angle | |
om=0 #initial angular velocity | |
u=0 #torque | |
y0 = [om, th] #initial values | |
t = linspace(0, 40, 4000) # | |
def f(y, t): | |
mu=0.1 #friction factor | |
m=1 #mass | |
g=9.81 #grav. acceleration | |
l=1 #length | |
return (y[1], | |
((-mu*y[1]) + (m*g*l*sin(y[0])) + u)/(m*(l**2))) | |
r = odeint(f, y0, t) | |
#print(r) | |
#plot(t,r) | |
subplot(211),plot(t,r[:,1]),xlabel('Angle'),ylabel('') | |
subplot(212),plot(t,r[:,0],'r'),xlabel('Angular velocity'),ylabel('') | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment