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.
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 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.
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