In this video we are going to be bridging the gap between the math covered in the last 3 videos (which includes Newton’s Universal law of gravitation, Ordinary differential equations, and ODE solvers) and how to apply all those equations into Python to create orbital mechanics simulations.
Link to GitHub repository: [ Ссылка ]
We’ll start with a quick review of Newton’s universal law of gravitation and how we’re going to plug it into Python. This equation tells us how to calculate the acceleration of a spacecraft given a position vector from the central body. This is a 2nd order differential equation because the output (acceleration) is the second derivative of the position. The goal is to calculate the position vectors vs. time, so we are going to have to integrate twice to achieve this.
Next we’ll review the Runge-Kutta methods of solving ordinary differential equation
Its important to understand that Runge-Kutta methods are 1st order ODE solvers, meaning that they can only do 1 integration at a time. So given acceleration, they can calculate velocity. Given velocity, they can calculate position. But they cannot directly calculate position only given an acceleration.
The most important part to understand is why Runge-Kutta solvers are first order ODE solvers. To calculate the next velocity given the acceleration weighted mean, we simply multiply that value by the step size (recall that this corresponds to calculating the area under the acceleration curve).
In this case, the step size has units of seconds and acceleration has units of km per seconds squared. So if we take a look at the units equation, we see that when we multiply step size times the acceleration weighted mean, this corresponds to multiplying seconds by km per second squared, this gives us km/s, which is velocity. So by multiplying by the step size, we have done 1 integration. We’ve calculated the next velocity given its derivative, acceleration.
But notice that we only calculate velocity here, but what we really want is the next position. So how are we then able to solve this 2nd order differential equation with a 1st order ODE solver?
So instead of our state vector only being position (which as we saw in the last slide would not be sufficient), we now add velocity to it. This is also necessary because we cannot fully describe an orbit just by a position vector. Notice the plot on the right. They all have the same initial position vector, but they all have different initial velocity vectors, which leads to very different results for their orbits.
So now lets get to the derivatives.
In our case, the derivative of position is velocity (in X, Y, and Z), and the derivative of velocity is acceleration (in X, Y, and Z). We calculate our acceleration from Newton’s universal law of gravitation
And we already know the velocity from our state!
Now that we established our state variables and their derivatives, we can plug them into a function in Python called two_body_ode, which as an input takes in the current time in the simulation and the state, and outputs the derivatives of our states.
Links to the Space Engineering Podcast (YouTube, Spotify, Google Podcasts, SimpleCast):
[ Ссылка ]
[ Ссылка ]
[ Ссылка ]
[ Ссылка ]
Link to Orbital Mechanics with Python video series:
[ Ссылка ]
Link to Spacecraft Attitude Control with Python video series:
[ Ссылка ]
Link a Mecánica Orbital con Python (videos en Español):
[ Ссылка ]
Link to Numerical Methods with Python video series:
[ Ссылка ]
#odesolvers #orbitalmechanics #astrodynamics
![](https://s2.save4k.ru/pic/TzX6bg3Kc0E/mqdefault.jpg)