Free fall of a body from a height
#Free Fall-Euler Method neglect air resistance
from pylab import*
t,v=0,0 #initialise the values
g=-9.8
dt=0.01
h=input('Enter the height of fall: ')tdat,hdat,vdat,gdat=[],[],[],[]
print 'time\theight\tvelocity\tacceleration\t'
while h>=0:
a=g
v+=a*dt
h+=v*dt
t+=dt
tdat.append(t)
hdat.append(h)
vdat.append(v)
gdat.append(a)
print '%10.3f\t%10.3f\t%10.3f\t%10.3f\t'%(t,h,v,a)
subplot(1,3,1)
title('position-time')
plot(tdat,hdat)
subplot(1,3,2)
plot(tdat,vdat)
title('Velocity-time')
subplot(1,3,3)
title('Acceleration-time')
plot(tdat,gdat)
show()
#Free Fall-Euler Method with air resistance
from pylab import*
t,v=0,0 #initialise the values
g=-9.8
dt=0.01
h=input('Enter the height of fall: ')
tdat,hdat,vdat,gdat=[],[],[],[]
print 'time\theight\tvelocity\tacceleration\t'
while h>=0:
a=g-v*.5
v+=a*dt
h+=v*dt
t+=dt
tdat.append(t)
hdat.append(h)
vdat.append(v)
gdat.append(a)
print '%10.3f\t%10.3f\t%10.3f\t%10.3f\t'%(t,h,v,a)
subplot(1,3,1)
title('position-time')
plot(tdat,hdat)
subplot(1,3,2)
plot(tdat,vdat)
title('Velocity-time')
subplot(1,3,3)
title('Acceleration-time')
plot(tdat,gdat)
show()
from pylab import*
t,v=0,0 #initialise the values
g=-9.8
dt=0.01
h=input('Enter the height of fall: ')tdat,hdat,vdat,gdat=[],[],[],[]
print 'time\theight\tvelocity\tacceleration\t'
while h>=0:
a=g
v+=a*dt
h+=v*dt
t+=dt
tdat.append(t)
hdat.append(h)
vdat.append(v)
gdat.append(a)
print '%10.3f\t%10.3f\t%10.3f\t%10.3f\t'%(t,h,v,a)
subplot(1,3,1)
title('position-time')
plot(tdat,hdat)
subplot(1,3,2)
plot(tdat,vdat)
title('Velocity-time')
subplot(1,3,3)
title('Acceleration-time')
plot(tdat,gdat)
show()
from pylab import*
t,v=0,0 #initialise the values
g=-9.8
dt=0.01
h=input('Enter the height of fall: ')
tdat,hdat,vdat,gdat=[],[],[],[]
print 'time\theight\tvelocity\tacceleration\t'
while h>=0:
a=g-v*.5
v+=a*dt
h+=v*dt
t+=dt
tdat.append(t)
hdat.append(h)
vdat.append(v)
gdat.append(a)
print '%10.3f\t%10.3f\t%10.3f\t%10.3f\t'%(t,h,v,a)
subplot(1,3,1)
title('position-time')
plot(tdat,hdat)
subplot(1,3,2)
plot(tdat,vdat)
title('Velocity-time')
subplot(1,3,3)
title('Acceleration-time')
plot(tdat,gdat)
show()
Comments
Post a Comment