Note: This is a very rough draft. Please bear with the changes. :)
Numerical methods are algorithms designed to approximate solutions to numerical problems. The following webpage will someday illustrate the differences between four such methods, namely the Euler, Euler-Cromer, Runge-Kutta, and Adams–Bashforth methods.
One of the simplest differential equations describing circular motion is
This may be written as a system of two equations:
Using Euler's method, we can derive formulas expressing x(t + h) and v(t + h) using x(t), v(t), and h, where h is the time step:
If at time t = 0, we have x(0) and v(0) = 1, we can let h = 0.01, make 1000 time steps, and plot the plane portrait of the system. With a little intuition, we find the following satisfies the initial conditions:
We can now re-write the equations:
We first consider the forces present in our toy model, two-body system. We define our system as having constant mass and no external force present. Newton's law of universal gravitation defines the gravitational force between two spherical objects of mass m1 and m2 separated by distance r as
where γ is the universal gravitational constant, approximately equal to γ = 6.673 × 10−11 N m2 kg−2. The unit vector r originates from the center-of-mass of m1 towards the center-of-mass of m2, and by definition may be rewritten as r / ||r||. Doing so, our equation for the gravitational force becomes:
Newton's second law states that a force acting on a point of mass will lead to a change in momentum per unit time:
We can set the above two equations equal to get
which may be reduced to a pair of coupled first-order ordinary differential equations:
Dividing both sides of the above by $m_{1}$, we receive the following expression for the acceleration of object 1:
Additionally, we can write the acceleration of object 2 as:
We then translate Equations 7 and 8 into the functions accel_obj1()
and accel_obj2
, respectively:
The total energy of a two-body system equals the sum of object 1's kinetic energy $(T_{1})$, object 2's kinetic energy $(T_{2})$, and the potential energy $(U)$ of the system:
Both kinetic and potential energy may be represented as a function of time:
We create the function energy()
for a more explicit view of how each numerical method influences the behavior of a system's total energy over time:
Given an initial condition, Euler's method may be used to obtain a numerical solution to first-order differential equations. The method states that the value of a differentiable function at $t+\delta{t}$ may be approximated as $f(t+\delta{t}) \approx f(t)+f'(t)\times\delta{t}$, where $\delta{t}$ is called the ``time step.'' Note: Euler's Method is simply the first two terms of a Taylor Series.
We derive formulas for the position $r_{k}(t+\delta{t})$ and momentum $m_{k}v_{k}(t+\delta{t})$ at each time step as follows:
For the purpose of our code, we rewrite $\textnormal{Eq.}\,(11)$ as:
These functions are directly used in our code. $\textnormal{Eqs.}\,(14)$ and $(12)$ are translated to Python as v_obj1[t+1]
and r_obj1[t+1]
, respectively.
Since the Euler method is highly susceptible to error, computations should utilize small time steps over a large number of iterations for the highest accuracy. To illustrate, we gradually decrease the time step and increase the number of iterations in our algorithm. We begin with t = 1000 and dt = 0.01; the two bodies are initially attracted to each other, only to both be rapidly ejected from the system.
Even decreasing the time step by $10\%$ for a step size value of $dt=0.001$ gives us a much different picture:
When we decrease the time step by $100\%$ and increase the number of iterations by $500\%$, it becomes clear that energy is not being conserved.
The orbits may be "tightened" by continuing to increase the number of iterations and decrease the size of each time step. At this point, any further fine-tuning may result in a non-trivial rise in processing time. It becomes clear that this method is computationally expensive and impractical for use in modeling.
The Euler-Cromer (or predictor-corrector) method mitigates the spiraling seen in the previous section with a small change. The \lstinline{for}-loop used in the Euler method is altered so that
becomes
and
becomes
While this change may seem trivial, the result is a markedly more efficient program with higher accuracy.
Interesting photos will go here.
1. Garcia, A.L., 2017, Numerical Methods for Physics (Python), pp. 350.