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

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
########################## # 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2010 for the course PHYS phy503 taught by Professor Gladden during the Spring '09 term at Ole Miss.

Page1 / 3

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online