#projectile motion
from pylab import*
from math import*
ax=0
ay=-9.8
theta=30
v=20
vx0=v*cos(theta*pi/180)
vy0=v*sin(theta*pi/180)
x0=0
y0=0
t=0 #initial time
h=0.001 #time step size
xdat=[x0]
ydat=[y0]#position data stored here
vdat=[v]#velocity data store here
time=[t]#time stored here
while(y0>=0):
x1=x0+h*vx0
y1=y0+h*vy0
vx1=vx0+h*ax
vy1=vy0+h*ay
xdat.append(x1)
ydat.append(y1)
vdat.append(sqrt(vx1*vx1+vy1*vy1))
time.append(t)
x0=x1
y0=y1
vx0=vx1
vy0=vy1
t=t+h
figure(1)
title("Motion of Projectile")
xlabel(" x")
ylabel("y")
plot(xdat,ydat,"r-")
figure(2)
title("Motion of projectile")
xlabel(" Time")
ylabel("Velocity")
plot(time,vdat,"k-")
show()
No comments:
Post a Comment