*Enlace a Spanish version
Materials: [ Cód.: NbodySim.m ] [ PDF ]
This video discusses the Matlab simulation code for the gravitational interaction of bodies (just 2D planar motion, for simplicity). The actual ODE simulator is ode113, and the state equation is that the derivative of the position is the velocity and the derivative of the velocity is the acceleration of gravity (Newton formula). Each body has position ‘x’ and position ‘y’ as well as velocities, so the total order of the system of differential equations is . All the loop code that calculates the forces for all pairs of bodies and the resulting acceleration for each body is explained.
The final part of the video briefly discusses the code for animating object motions, simply with plot.´
Actual examples of simulations with several number of bodies, Kepler laws and
escape velocity are illustrated in video [
*Link to my [ whole collection] of videos in English. Link to larger [ Colección completa] in Spanish.