Search This Blog

Friday, June 10, 2011

Simulation free fall of a body

#Free fall of a body
#We are solving two first order differential equations by Euler method
#1. dy/dt=v initial condition y0
#2. dv/dt=a initial condition v0


from pylab import*
from math import*

a=-9.8 #acceleration 
v0=0.0 #initial velocity
y0=100 #initial height
t=0 #initial time
h=0.01 #time step size
ydat=[y0]#position data stored here
vdat=[v0]#velocity data stored here
time=[t]#time stored here

#Implementation Euler method
while(y0>0):
    y1=y0+h*v0
    v1=v0+h*a
    t=t+h
    ydat.append(y1)
    vdat.append(fabs(v1))
    time.append(t)
    y0=y1
    v0=v1
   
figure(1)
title("Free fall of a body")
xlabel(" Time")
ylabel("Position")
plot(time,ydat)


figure(2)
title("Free fall of a body")
xlabel(" Time")
ylabel("Velocity")
plot(time,vdat)
show()

1 comment: