Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Modeling Constant Acceleration
For an object that is accelerating, you need to update the velocity at each time step in addition to updating the position. The easiest way to update velocity is to use the definition of average acceleration:
Because of the way compute programs work, the line ball.vel = ball.vel + g*dt
is equivalent to the above equation. In other words, Python calculates everything to the right of the equals sign and then assigns it to the variable to the left. This means that ball.vel
on the right side is the initial velocity , while ball.vel
on the left side is actually the final velocity .
Run the code below to see a ball moving with a constant gravitational force. You'll need to click on the animation frame to get the motion started.
The ball leaves a trail behind it because of the attach_trail()
command. The arrow pointing in the direction of motion is from the attach_arrow()
command.
The two graphs below the animation frame dispaly the y-position vs. time graph and the y-velocity vs. time graph.
For You To Try
Add a second object with a different initial velocity
Add curves to both graphs for this new object and plot the y-position and y-velocity
For You To Try
Plot the analytical solution for the y-position on the graph to compare to the computational result
To compare this result to the exact analytical result () to the computed results, we can plot the analytical solution on the same graph as the position. To do this you will need to add another gcurve()
to the first graph screen. Create another gcurve
called pos_exact_graph
and insert the code below where it says ### Add code for pos_exact_graph here
. Give the curve a different color.
Next you will need to plot the graph. You can do this inside the while loop by calculating the y-position using and then calling pos_exact_graph.plot()
to plot the exact position vs. time. All of this code can go where it says ###Add code to calculate position using analytical equation and plot it here.
I recommend shifting for the exact solution up 1 m so the two curves are slightly shifted.
Once you are done you can move on to Motion Diagrams in VPython.