%matplotlib inline
from daomath.daomechanics import VectorField
from daomath.daomechanics import MaterialPoint
from daomath.ground import Ground
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML
import numpy as np
Solving of the system non-linear differential equations using LeapFrog algorithm.So we will able to to calculate the body's motion according second principle of mechanics We will visualize the motions by Python lib pyplot,thus we will attain more understanding of what is vector field ,the innitial values ploblems and so on.In addition we will show the law of conservation of energy
The priciple of meachanics defined by Nuton,help up to calculate and predict the motion of body when we known the force wich act on it and its inition values of velosaty and radius vector
Vector field in two dimensions is a function that assigns to each point (x,y) of the xy-plane a two-dimensional vector F(x,y). The standard notation is →F(x,y)=V(x,y).→i+Q(x,y).→j
The most famous example is force on Earh'surface →G(x,y)=0.→i−g.→j
f = VectorField(lambda t,x,y : 0 , lambda t,x,y : -9.8)
f.plot_field(reduce=8,scale=10,width=0.003,label=r'$\vec{g}$')
plt.show()
Other Field : →F(x,y)=−x.→i−y.→j
f = VectorField(lambda t,x,y : -x , lambda t,x,y : -y)
f.plot_field(reduce=4,scale=10,width=0.003)
plt.show()
1)d→pdt=m.d2→r(t)dt2=m.→dv(t,→r)dt=m.→a(t,→r)dt=→F(→r,t)
The motion of the body on wich acts →F(x,y)=0.→i−g.→j
The solving of differcial eqation is verry simple ∫→vdt=∫0.dt.→i−∫g.dt.→j+∫→v0dt=20.cos45∘.→i+(20.sin45∘−g.t).→j
fig = plt.figure(figsize=(6, 6))
fig = plt.figure(figsize=(6, 6))
u = lambda t, x, y: 0
v = lambda t, x, y: -10
point = MaterialPoint(x0=0, y0=0, mass=1)
f = VectorField(u, v)
point.add_force(f)
z = point.calculate_radius_vector(20*np.cos(np.pi/4), +50*np.sin(np.pi/4),n=700)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(40))
print(size)
anim = animation.FuncAnimation(plt.gcf(), point.update_HTML_animation,interval=100,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
17
<Figure size 432x432 with 0 Axes>
let's to see radius vector
plt.plot(z[:,0],z[:,1])
point.plot_radios_vector()
if we change the the initial velosity for exampe (0,50) we will see
fig = plt.figure(figsize=(6, 6))
fig = plt.figure(figsize=(6, 6))
z = point.calculate_radius_vector(0, 50,n=1000)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(20))
anim = animation.FuncAnimation(plt.gcf(), point.update_HTML_animation,interval=100,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
<Figure size 432x432 with 0 Axes>
fig = plt.figure(figsize=(6, 6))
fig = plt.figure(figsize=(6, 6))
z = point.calculate_radius_vector(10, 70,n=1000)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(20))
anim = animation.FuncAnimation(plt.gcf(), point.update_HTML_animation,interval=100,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
<Figure size 432x432 with 0 Axes>
Gravity →G=−M.m.x(x2+y2)3/2→i−M.m.y(x2+y2)3/2→j
fig = plt.figure(figsize=(6, 6))
point = MaterialPoint(x0=10,y0=10)
# z = point.calculate_radius_vector(3,4)
# anim = animation.FuncAnimation(fig, point.update_HTML_animation, fargs=(Q, X, Y),
# interval=50, blit=False)
u = lambda t, x, y: -80 * x / ((x ** 2 + y ** 2) ** (3 / 2))
v = lambda t, x, y: -80 * y / ((x ** 2 + y ** 2) ** (3 / 2))
point = MaterialPoint(x0=7, y0=7, mass=1)
f = VectorField(u, v)
point.add_force(f)
z = point.calculate_radius_vector(-1*np.cos(np.pi/4), -4*np.sin(np.pi/4),5000,h=0.005)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(100))
anim = animation.FuncAnimation(fig, point.update_HTML_animation,interval=50,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
we can notice that the velocity near to center (0,0) is most fast if we change v1=−10.cos45∘,v2=−5.sin45∘
fig = plt.figure(figsize=(6, 6))
point = MaterialPoint(x0=10,y0=10)
# z = point.calculate_radius_vector(3,4)
# anim = animation.FuncAnimation(fig, point.update_HTML_animation, fargs=(Q, X, Y),
# interval=50, blit=False)
u = lambda t, x, y: -80 * x / ((x ** 2 + y ** 2) ** (3 / 2))
v = lambda t, x, y: -80 * y / ((x ** 2 + y ** 2) ** (3 / 2))
point = MaterialPoint(x0=7, y0=7, mass=1)
f = VectorField(u, v)
point.add_force(f)
z = point.calculate_radius_vector(-10*np.cos(np.pi/4), -5*np.sin(np.pi/4),n=1000,h=0.003)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(100))
anim = animation.FuncAnimation(fig, point.update_HTML_animation,interval=50,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
we can notice that the body is gone to out of orbit and just passed near to source of gravity .because the force is not strong enought to change the initial velocity.
In the last example will be shown how the stability of LeapFrog integration , when we change the intergration step h = 0.5
fig = plt.figure(figsize=(6, 6))
point = MaterialPoint(x0=10,y0=10)
# z = point.calculate_radius_vector(3,4)
# anim = animation.FuncAnimation(fig, point.update_HTML_animation, fargs=(Q, X, Y),
# interval=50, blit=False)
u = lambda t, x, y: -80 * x / ((x ** 2 + y ** 2) ** (3 / 2))
v = lambda t, x, y: -80 * y / ((x ** 2 + y ** 2) ** (3 / 2))
point = MaterialPoint(x0=10, y0=10, mass=1)
f = VectorField(u, v)
point.add_force(f)
z = point.calculate_radius_vector(-1*np.cos(np.pi/4), -4*np.sin(np.pi/4),7000,h=0.5)
plt.plot(z[:,0],z[:,1])
size = int(point.get_size(100))
anim = animation.FuncAnimation(fig, point.update_HTML_animation,interval=50,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
Wow!!!
We've attain the entirely different result.
The error growth factor is increased when the integration factor also increase . After many oscillation this error become enormous
Work is the product of force and distance. In physics, a force is said to do work if, when acting, there is a movement of the point of application in the direction of the force. For example, when a ball is held above the ground and then dropped, the work done on the ball as it falls is equal to the weight of the ball. The work of system by definition is integral of dW where dW=→F.d→r=m.→a.d→r
T is kinetic V potential energy E+U=H
accordingly theorem of Green if ∫C→▽×→F=0
For the first time in above example,we've saw the low of conservation .How does kinetic energy is transformed to potential energy and inverse process is the same .The most famous example is gravity on earth's surface:
m.g.y−m.g.yo=E−E0⇔E=H−m.g.y
There are many kinds of transformation of energy ,maybe that is the most deeply and fundamental law in physics. Let's see other kind of conversation - The Law of Momentum Conservation Consider a collision between two objects.-obeject 1 and object 2 Newton's third law says the force in moment of collision between obj1 and obj2 is equal in their magnitude and opposite in their direction 1)→F12=−→F21
let's multiple equation 1) with dt and after that we can integrate it →F12=−→F21
Let see what 's happens with energy conversation: After the multiplacation of eaqution 1) on both sides with →dr
Let's see visualization of collision between to body
fig = plt.figure(figsize=(6, 6))
fig = plt.figure(figsize=(6, 6))
g = Ground()
g.add_point(MaterialPoint(x0=0, y0=5, mass=5, v_x0=3, v_y0=0))
g.add_point(MaterialPoint(x0=10, y0=5, mass=15, v_x0=-3, v_y0=0))
g.calculate_speed_points(end_time=80)
points = g.points
size = len(g.points[0].x_args)
anim = animation.FuncAnimation(fig, g.update_HTML_animation,interval=80,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
<Figure size 432x432 with 0 Axes>
After the collion we can notice that the red ball is smaller velositt before colion, because its mass greater than blue ball. That fact comes from The fact H=E1+E2,Ei=H2
fig = plt.figure(figsize=(6, 6))
fig = plt.figure(figsize=(6, 6))
g = Ground()
g.add_point(MaterialPoint(x0=10, y0=10, mass=4, v_x0=-2, v_y0=-2))
g.add_point(MaterialPoint(x0=5, y0=10, mass=3, v_x0=-2, v_y0=-2))
g.add_point(MaterialPoint(x0=0, y0=0, mass=10, v_x0=2, v_y0=2))
g.add_point(MaterialPoint(x0=0, y0=10, mass=12, v_x0=2, v_y0=-2))
g.add_point(MaterialPoint(x0=10, y0=0, mass=20, v_x0=-2, v_y0=2))
g.add_point(MaterialPoint(x0=4, y0=10, mass=15, v_x0=-2, v_y0=-2))
g.add_point(MaterialPoint(x0=0, y0=5, mass=6, v_x0=2, v_y0=-4))
g.add_point(MaterialPoint(x0=10, y0=5, mass=8, v_x0=-2, v_y0=2))
g.calculate_speed_points(end_time=100)
points = g.points
size = len(g.points[0].x_args)
anim = animation.FuncAnimation(fig, g.update_HTML_animation,interval=40,fargs=(fig,),frames=size, blit=False)
HTML(anim.to_html5_video())
<Figure size 432x432 with 0 Axes>
The total energy of closed mechanics system in which does not act any external forces remains the same dHdt=∑dEidt=0⇔H=Const
REFERENCES:
[1] https://en.wikipedia.org/wiki/Work_(physics)
[2] Numerical Methods for Solving Systems of Nonlinear Euqtions by Courtney Remani
[3] http://www.astro.utu.fi/~cflynn/galdyn/lecture6.html?fbclid=IwAR31E-ezjjqEmMxxui7CkpEjrc32ACuMErAHQgK1sSsaifNRv2ss3FcPGaY
[4] https://www.quora.com/What-is-the-relationship-between-mass-and-velocity
[5] Stability of the Leapfrog/Midpoint Method