{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec15_ODE2

# lec15_ODE2 - Example 1 Simple Pendulum using Verlet from...

This preview shows pages 1–3. Sign up to view the full content.

########################## # Example 1: Simple Pendulum using Verlet ########################## from pylab import * def euler(r,v,tau): for k in range(maxstep-1): vc=v[k] rc=r[k] t=k*tau times[k]=t #Theory with no drag for comaprison theta_saa[k]=thetai*cos(w*t) #Compute accel. vector at each time k acc=-g*sin(rc) #Compute r and v for next time k v[k+1] = vc + tau* acc r[k+1] = rc+tau*vc times[-1]=maxstep*tau return r,v def verlet(r,v,tau): v[1] = v[0] - g*sin(r[0])*tau r[1]=r[0]-tau*v[1] for k in range(1,maxstep-1): t=k*tau times[k]=t #Theory with no drag for comaprison theta_saa[k]=thetai*cos(w*t) acc=-g*sin(r[k]) r[k+1] = 2*r[k] - r[k-1] +tau**2*acc v[k+1] = (r[k+1] - r[k-1])/(2*tau) times[-1]=maxstep*tau return r,v close('all') #Initial conditions thetai=170.*pi/180 vi=0.0 #Simulation parameters tau=0.001 maxstep=10000 #Create container 2-D arrays for position, velocity and theory position theta=zeros(maxstep) v=zeros(maxstep) theta_saa=zeros(maxstep) times=zeros(maxstep) theta[0]=thetai

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
v[0]=vi #Pendulum Physics g=9.81 L=0.3 w=sqrt(g/L) #Convert to angular acceleration g=g/L #theta,v=euler(theta,v,tau) theta,v = verlet(theta,v,tau)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

lec15_ODE2 - Example 1 Simple Pendulum using Verlet from...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online