︠4bf0d081-e063-43f5-8977-07852df7a142i︠ %html

Ball motion with Sage

Jose Guzman(*) and Ignacio Delgado

version 1.0.1

December 09, 2009

(*) This file is under construction. Please send any suggestions or comments to nin@neurohost.org


 

Index

  1. Introduction
  2. Ball motion equation
  3. Solving the equation with Sage
  4. Graphic representation

1. Introduction:

We will consider the equation to describe the vertical motion of a ball, and analyze and solve with Sage. Code is extensively commented through the notebook and should be self-explanatory. Comments and suggestions are greatly appreciated.

 

2. Ball motion equation:

From Newton's second law of motion we can write a mathematical formulation of a ball motion. With this equation we can calculate the ball's  vertical position (y) according to the time as follows:

$y(t) = V_ot -\frac{1}{2}gt^2$

where $y$ is the vertical distance, $V_o$ is the initial velocity of the ball, $g$ is the acceleration of gravity, and $t$ is time.

︡6661011c-5169-4b96-9f7c-8fdf42b2ac83︡{"html": "
\r\n

Ball motion with Sage

\r\n

Jose Guzman(*) and Ignacio Delgado

\r\n

version 1.0.1

\r\n

December 09, 2009

\r\n

(*) This file is under construction. Please send any suggestions or comments to nin@neurohost.org

\r\n
\r\n

 

\r\n

Index

\r\n
    \r\n
  1. Introduction
  2. \r\n
  3. Ball motion equation
  4. \r\n
  5. Solving the equation with Sage
  6. \r\n
  7. Graphic representation
  8. \r\n
\r\n
\r\n

\r\n

1. Introduction:

\r\n

We will consider the equation to describe the vertical motion of a ball, and analyze and solve with Sage. Code is extensively commented through the notebook and should be self-explanatory. Comments and suggestions are greatly appreciated.

\r\n

 

\r\n

2. Ball motion equation:

\r\n

From Newton's second law of motion we can write a mathematical formulation of a ball motion. With this equation we can calculate the ball's  vertical position (y) according to the time as follows:

\r\n

$y(t) = V_ot -\\frac{1}{2}gt^2$

\r\n

where $y$ is the vertical distance, $V_o$ is the initial velocity of the ball, $g$ is the acceleration of gravity, and $t$ is time.

"}︡ ︠43e770bf-22cc-47c3-bf04-f512024b58eb︠ # define equation var('t,v0,g') # symbolic variables y(t)=v0*t-(g*t**2)/2 # ball motion equation #result = y.subs(v0=5,g=9.81,t=1) #print result.pyobject() # we need pyobject() to get the value ︡08771877-8109-41aa-a63d-90910f59d962︡︡ ︠068557f7-cc50-43c5-8233-4df903fdb7f3i︠ %html

3. Solving the equation with Sage:

We can look for for solutions to the equation a y=0, to know the time it takes for the ball to move upwards and returns to y again.

$V_ot -\frac{1}{2}gt^2 =0 ; t(V_o -\frac{1}{2}gt) = 0$

We have two possible solutions, corresponding to

$t=0$ or $t=2V_o/g$

We can easily solve this with Sage.

︡0fae2c8d-f379-4b9a-84e3-a0dee576e837︡{"html": "

3. Solving the equation with Sage:

\r\n

We can look for for solutions to the equation a y=0, to know the time it takes for the ball to move upwards and returns to y again.

\r\n

$V_ot -\\frac{1}{2}gt^2 =0 ; t(V_o -\\frac{1}{2}gt) = 0$

\r\n

We have two possible solutions, corresponding to

\r\n

$t=0$ or $t=2V_o/g$

\r\n

We can easily solve this with Sage.

"}︡ ︠abf2755d-edad-42fa-bf54-285d7ae947e1︠ solve(y==0,t) # solve equation y=0 with respect to t ︡73c7817f-a836-4b4d-975a-0159141aa12d︡{"stdout": "[t == 2*v0/g, t == 0]"}︡ ︠c77262c7-93c6-4b91-89e7-d1a9edd4ededi︠ %html

We can calculate the maximal vertical distance reached by simply taking the derivative of the function and solve it against time.

${\displaystyle\frac{dy}{dt}=V_o -gt}$

Once Again, Sage allows us to perform this simple calculation.

︡5cc0fdf7-107b-436b-996e-02d70e23d37b︡{"html": "

We can calculate the maximal vertical distance reached by simply taking the derivative of the function and solve it against time.

\r\n

${\\displaystyle\\frac{dy}{dt}=V_o -gt}$

\r\n

Once Again, Sage allows us to perform this simple calculation.

"}︡ ︠67676ecd-9e14-4575-8e42-f5e930a07860︠ diff(y,t) # calculate dy/dt ︡dbe979d5-7e86-4cc4-b3b1-f7e317647485︡{"stdout": "t |--> -g*t + v0"}︡ ︠14fc8ffb-a448-4a42-8e81-269c178e63edi︠ %html

If we equal the equation to zero.

${\displaystyle\frac{dy}{dt}=V_o -gt=0 :}$

 we can calculate the time at which the maximum vertical distance is reached

$t=V_o/g$

In Sage, we simply solve the differential equation with respect to t.

︡5dee036f-a622-4ba4-8a1e-31cc971cfc3c︡{"html": "

If we equal the equation to zero.

\r\n

${\\displaystyle\\frac{dy}{dt}=V_o -gt=0 :}$

\r\n

 we can calculate the time at which the maximum vertical distance is reached

\r\n

$t=V_o/g$

\r\n

In Sage, we simply solve the differential equation with respect to t.

"}︡ ︠27f79e4f-b73c-49ca-b399-04f1fa58a412︠ solve(diff(y,t)==0,t) ︡2e543a66-35a9-4b54-8532-560da2a46fbe︡{"stdout": "[t == v0/g]"}︡ ︠b5a4f761-a620-445d-9289-4d9caf328980i︠ %html

4. Graphic representation:

We can plot it now all together.

︡e3de5140-2761-4e27-b082-8e5133c192f1︡{"html": "

4. Graphic representation:

\r\n

We can plot it now all together.

"}︡ ︠ce45c5fc-1135-40f0-a50d-488e00a829fb︠ import numpy as np class Hyperbola(): def __init__(self, velocity, color): """ creates a hyperbolic curve of the ball motion at a given initial velocity. Arguments: velocity -- initial velocity color -- color to plot the curve """ # public variables #f(v) = v*t - (g*t**2)/2 v,t=var('v,t') # symbolic variables g=9.81 self._v = velocity self._color = color self.f = velocity*t - (g*t**2)/2 # this only depends on t now self._tend = 2*velocity/g self.__g=9.81 self._tmax = self._v/self.__g def maxcoor(self): """ returns x,y coordinates of the point at the maximum """ ymax = self.f(self._tmax) return (self._tmax, ymax) def plot(self): """ creates a plot object with the curve, label, maximun point and the coordinates of the max point """ curve = plot(self.f,0,self._tend,rgbcolor=self._color) circle = point(self.maxcoor(), rgbcolor='white', pointsize=30,faceted=True) location = (self._tmax,self.f(self._tmax)*1.2) label = text("V=%s m/s"%self._v, location,rgbcolor=self._color) return curve + circle + label # plot functions # create some objects myfunc = Hyperbola(velocity=6,color='orange') #print myfunc.plot() #print myfunc.maxcoor() figure = myfunc.plot() v=[2,3,4,5] # list of velocities colors = ['red','green','black','blue'] # list of colors for i,j in zip(v,colors): myfun = Hyperbola(velocity=i, color=j) figure += myfun.plot() figure.fontsize(14) figure.show(xmax=1.50) ︡1edd5168-65ff-4d3a-9eb2-488dac68987d︡{"html": ""}︡