@zy-0815
2016-10-16T22:37:26.000000Z
字数 10132
阅读 1127
张梓桐 第五次计算物理
With the base of Page 34 on textbook.I fantastically consider the track of an cannon shell with air resistance,density of air(both aidabatic and isothermal approximation),and the variation of gravity via altitude.
In this passage,we are going to talk about the different factors that may have effects on the movment of a cannon shell by Euler method.
Acquiring from the previous knowledge of the Euler applied into the Computational Physics,we now can conclude more relastic factors into the movement of a cannon shell.
Now I still want to stress the importance of Euler method in the projectile movement:
There will add one extra term in each equation of velocity:
With the law of Newton,
import pylab as pl
import math
class projectile():
def __init__(self,time_step=0.1,total_time=10,intial_velocity_x=50,\
intial_velocity_y=50, intial_x=0,intial_y=0,mass=10,B2=0.001,B1=0.001):
self.v_x=[intial_velocity_x]
self.v_y=[intial_velocity_y]
self.v=[math.sqrt(pow(intial_velocity_x,2)+pow(intial_velocity_y,2))]
self.x=[intial_x]
self.y=[intial_y]
self.dt=time_step
self.time=total_time
self.m=mass
self.B2=B2
self.B1=B1
self.intial_velocity_x=intial_velocity_x
self.intial_velocity_y=intial_velocity_y
def run(self):
_time=0
while(_time<self.time):
self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
self.v_x.append(self.v_x[-1]-(self.B2/self.m)*self.v[-1]*self.dt*self.v_x[-1])
self.x.append(self.v_x[-1]*self.dt+self.x[-1])
self.v_y.append(self.v_y[-1]-10*self.dt-(self.B1/self.m)*self.v[-1]*self.dt*self.v_y[-1])
self.y.append(self.v_y[-1]*self.dt+self.y[-1])
_time+=self.dt
def show_results(self):
pl.plot(self.x,self.y,label='angle is %f'%(math.atan(self.intial_velocity_y/self.intial_velocity_x)*180/math.pi))
pl.ylim(0,)
pl.title('With resistance')
pl.show
pl.legend()
a=projectile()
a.run()
a.show_results()
To obtain the movement withoud we only need to set and equal 0.And that becomes the ideal situation.
import pylab as pl
import math
class projectile():
def __init__(self,time_step=0.1,total_time=10,intial_velocity_x=50,\
intial_velocity_y=50, intial_x=0,intial_y=1,mass=10,B2=0.001,B1=0.001,F_0=5):
self.v_x=[intial_velocity_x]
self.v_y=[intial_velocity_y]
self.v=[math.sqrt(pow(intial_velocity_x,2)+pow(intial_velocity_y,2))]
self.x=[intial_x]
self.y=[intial_y]
self.dt=time_step
self.time=total_time
self.m=mass
self.B2=B2
self.B1=B1
self.F_0=F_0
self.intial_velocity_x=intial_velocity_x
self.intial_velocity_y=intial_velocity_y
def run(self):
_time=0
while(_time<self.time):
self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
self.v_x.append(self.v_x[-1]-\
(self.B2/self.m)*self.v[-1]*self.dt*self.v_x[-1]-\
self.F_0*pow(math.e,-self.y[-1]/self.y[0])*self.dt*self.v_x[-1]/(self.m*self.v[-1]))
self.x.append(self.v_x[-1]*self.dt+self.x[-1])
self.v_y.append(self.v_y[-1]-10*self.dt-\
(self.B1/self.m)*self.v[-1]*self.dt*self.v_y[-1]-\
self.F_0*pow(math.e,-self.y[-1]/self.y[0])*self.dt*self.v_y[-1]/(self.m*self.v[-1]))#isothermal term#
self.y.append(self.v_y[-1]*self.dt+self.y[-1])
_time+=self.dt
def show_results(self):
pl.plot(self.x,self.y,label='angle is %f'%(math.atan(self.intial_velocity_y/self.intial_velocity_x)*180/math.pi))
pl.ylim(0,)
pl.title('With resistance and isothermal altitude effect')
pl.show
pl.legend()
a=projectile()
a.run()
a.show_results()
Here you can see,the main differnece is in the 'run' classes,we change the fomula of and.
import pylab as pl
import math
class projectile():
def __init__(self,time_step=0.1,total_time=10,intial_velocity_x=50,\
intial_velocity_y=50, intial_x=0,intial_y=1,mass=10,B2=0.001,B1=0.001,F_0=5,alpha=2.5,a=0.0025,T_0=273):
self.v_x=[intial_velocity_x]
self.v_y=[intial_velocity_y]
self.v=[math.sqrt(pow(intial_velocity_x,2)+pow(intial_velocity_y,2))]
self.x=[intial_x]
self.y=[intial_y]
self.dt=time_step
self.time=total_time
self.m=mass
self.B2=B2
self.B1=B1
self.F_0=F_0
self.alpha=alpha
self.a=a
self.T_0=T_0
self.intial_velocity_x=intial_velocity_x
self.intial_velocity_y=intial_velocity_y
def run(self):
_time=0
while(_time<self.time):
self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
self.v_x.append(self.v_x[-1]-\
(self.B2/self.m)*self.v[-1]*self.dt*self.v_x[-1]-\
self.F_0*pow(1-self.a*self.y[-1]/self.T_0,self.alpha)*self.dt*self.v_x[-1]/(self.m*self.v[-1]))
self.x.append(self.v_x[-1]*self.dt+self.x[-1])
self.v_y.append(self.v_y[-1]-10*self.dt-\
(self.B1/self.m)*self.v[-1]*self.dt*self.v_y[-1]-\
self.F_0*pow(1-self.a*self.y[-1]/self.T_0,self.alpha)*self.dt*self.v_y[-1]/(self.m*self.v[-1]))#isothermal term#
self.y.append(self.v_y[-1]*self.dt+self.y[-1])
_time+=self.dt
def show_results(self):
pl.plot(self.x,self.y,label='angle is %f'%(math.atan(self.intial_velocity_y/self.intial_velocity_x)*180/math.pi))
pl.ylim(0,)
pl.title('With resistance and adiabatic altitude effect. ')
pl.legend()
pl.show
a=projectile()
a.run()
a.show_results()
Now take a look into the adiabatic,which is also a more precis situation of relastic situation,the formula is even mor complicated.
#For the calculation of graviety we use the formula:g(h)=\frac{GM}{(h+re)^{2}} to
#calculate,G means the gravational constant,M means the mass of sun,re is the raius of earth#
#For convenience,GM=4.03^10^13,re=6.371*10^6#
#Replace g=10 with g=(4.03*pow(10,14)/pow((self.y[-1]+6.371*pow(10,6)),2))#
import pylab as pl
import math
class projectile():
def __init__(self,time_step=0.1,total_time=10,intial_velocity_x=50,\
intial_velocity_y=50, intial_x=0,intial_y=1,mass=10,B2=0.001,B1=0.001,F_0=5,alpha=2.5,a=0.0025,T_0=273):
self.v_x=[intial_velocity_x]
self.v_y=[intial_velocity_y]
self.v=[math.sqrt(pow(intial_velocity_x,2)+pow(intial_velocity_y,2))]
self.x=[intial_x]
self.y=[intial_y]
self.dt=time_step
self.time=total_time
self.m=mass
self.B2=B2
self.B1=B1
self.F_0=F_0
self.alpha=alpha
self.a=a
self.T_0=T_0
self.intial_velocity_x=intial_velocity_x
self.intial_velocity_y=intial_velocity_y
def run(self):
_time=0
while(_time<self.time):
self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
self.v_x.append(self.v_x[-1]-\
(self.B2/self.m)*self.v[-1]*self.dt*self.v_x[-1]-\
self.F_0*pow(1-self.a*self.y[-1]/self.T_0,self.alpha)*self.dt*self.v_x[-1]/(self.m*self.v[-1]))
self.x.append(self.v_x[-1]*self.dt+self.x[-1])
self.v_y.append(self.v_y[-1]-(4.03*pow(10,14)/pow((self.y[-1]+6.371*pow(10,6)),2))*self.dt-\
(self.B1/self.m)*self.v[-1]*self.dt*self.v_y[-1]-\
self.F_0*pow(1-self.a*self.y[-1]/self.T_0,self.alpha)*self.dt*self.v_y[-1]/(self.m*self.v[-1]))#isothermal term#
self.y.append(self.v_y[-1]*self.dt+self.y[-1])
_time+=self.dt
def show_results(self):
pl.plot(self.x,self.y,label='angle is %f'%(math.atan(self.intial_velocity_y/self.intial_velocity_x)*180/math.pi))
pl.ylim(0,)
pl.title('With resistance,gravity and adiabatic altitude effect. ')
pl.legend()
pl.show
a=projectile()
a.run()
a.show_results()
Note that the maxium distance can bedetermined by the following code adding to the 'run':
if self.y[-1]<=0 and self.y[-2]>=0:
print "The maxium distance is %f" %self.x[-2]-self.y[-2]*(self.x[-1]-self.x[-2])/(self.y[-1]-self.y[-2])
For the calculation of graviety we use the formula:
Set the intial velocity being ,with angle being,,,and .
With the intial angle being , the mass being , velocity component being . The difference in resistance is shown in the track as:
It is obvious that the green one is with resistance,and its maxium height and ranges become smaller as the ideal one.In the above figure,we set .
Now we change the parameter,you can see the difference even more clearly.
We set ,and
From the above figure,we see in the isothermal situation,the track changes slightly before the maxium height,but differes greatly after the maxium height.
Here we set ,
It is evidently that the adiabatic process decrease greatly than the isothermal effect,and shows a characteristic of unsymmertic.
To make the difference even more clearly,I amplify the details to show:
, ,
As the altitude isn't so high,the gravation constant almost remains constan,which means little variation in the figure,just as we have expected!
And the detailed one:
(In the previous without gravational effect,we set ,so there may be some faluts with the last two rows.)
1.Matplotlib
2.Computational Physics
3.Tutorial-Chapter 2 Realistic Projectile Motion