# three_body_ode Planar Three Body Problem Simulation

three_body_ode, an Octave code which simulates the solution of the planar three body problem.

Three bodies, regarded as point masses, are constrained to lie in a plane. The masses of each body are given, as are the positions and velocities at a starting time T = 0. The bodies move in accordance with the gravitational force between them.

The force exerted on the 0-th body by the 1st body can be written:

```        F = - m0 m1 ( p0 - p1 ) / |p0 - p1|^3
```
assuming that units have been normalized to that the gravitational coefficient is 1. Newton's laws of motion can be written:
```
m0 p0'' = - m0 m1 ( p0 - p1 ) / |p0 - p1|^3
- m0 m2 ( p0 - p2 ) / |p0 - p2|^3

m1 p1'' = - m1 m0 ( p1 - p0 ) / |p1 - p0|^3
- m1 m2 ( p1 - p2 ) / |p1 - p2|^3

m2 p2'' = - m2 m0 ( p2 - p0 ) / |p2 - p0|^3
- m2 m1 ( p2 - p1 ) / |p2 - p1|^3
```

Letting

```        y1 = p0(x)
y2 = p0(y)
y3 = p0'(x)
y4 = p0'(y)
```
and using similar definitions for p1 and p2, the 3 second order vector equations can be rewritten as 12 first order equations. In particular, the first four are:
```        y1' = y3
y2' = y4
y3' = - m1 ( y1 - y5  ) / |(y1,y2) - (y5,y6) |^3
- m2 ( y1 - y9  ) / |(y1,y2) - (y9,y10)|^3
y4' = - m1 ( y2 - y6  ) / |(y1,y2) - (y5,y6) |^3
- m2 ( y2 - y10 ) / |(y1,y2) - (y9,y10)|^3
```
and so on. This first order system can be integrated by a standard ODE solver.

Note that when any two bodies come close together, the solution changes very rapidly, and very small steps must be taken by the ODE solver. For this system, the first near collision occurs around T=15.8299, and the results produced by MATLAB's ode113 will not be very accurate after that point.

### Languages:

three_body_ode is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and an Octave version.

### Related Data and codes:

arenstorf_ode, an Octave code which describes an ordinary differential equation (ODE) which defines a stable periodic orbit of a spacecraft around the Earth and the Moon.

biochemical_linear_ode, an Octave code which defines a linear biochemical ordinary differential equation (ODE).

biochemical_nonlinear_ode, an Octave code which defines a nonlinear biochemical ordinary differential equation (ODE).

brusselator_ode, an Octave code which defines the Brusselator ordinary differential equation (ODE) system.

double_pendulum_ode, an Octave code which defines the double pendulum ordinary differential equation (ODE).

flame_ode, an Octave code which considers an ordinary differential equation (ODE) which models the growth of a ball of flame in a combustion process.

henon_heiles_ode, an Octave code which solves the Henon-Heiles system of ordinary differential equations (ODEs) which model the motion of a star around the galactic center.

humps_ode, an Octave code which solves an ordinary differential equation (ODE) whose solution is a double hump curve.

kepler_ode_test an Octave code which considers an ordinary differential equation (ODE) which models a Kepler two-body gravitational problem.

kepler_perturbed_ode an Octave code which considers an ordinary differential equation (ODE) which models a perturbed Kepler two-body gravitational problem.

lorenz_ode, an Octave code which approximates solutions to the Lorenz system, creating output files that can be displayed by gnuplot.

normal_ode, an Octave code which sets up an ordinary differential equation (ODE) for the normal probability density function (PDF).

oscillator_ode, an Octave code which defines the highly oscillatory ordinary differential equation (ODE).

pendulum_nonlinear_ode, an Octave code which sets up the ordinary differential equations (ODE) that represent a nonlinear model ofthe behavior of a pendulum of length L under a gravitational force of strength G.

pendulum_ode, an Octave code which sets up the ordinary differential equations (ODE) that represent a linear model ofthe behavior of a pendulum of length L under a gravitational force of strength G.

predator_prey_ode, an Octave code which solves a pair of predator prey ordinary differential equations (ODE).

quadex_ode, an Octave code which solves a stiff ordinary differential equation (ODE), whose exact solution is a parabola, but for which errors grow exponentially.

quasiperiodic_ode, an Octave code which sets up a system of ordinary differential equations (ODE) for a problem with a quasiperiodic solution.

robertson_ode, an Octave code which sets up a system of three nonlinear stiff ordinary differential equations (ODE) characterizing an autocatalytic chemical reaction.

roessler_ode, an Octave code which defines the right hand side of the Roessler ODE system, which exhibits chaotic behavior.

rubber_band_ode, an Octave code which defines and solves a set of ordinary differential equations (ODE) describing a mass suspended by a spring and rubber band, which can exhibit chaotic behavior.

sir_ode, an Octave code which sets up the ordinary differential equations (ODE) which simulate the spread of a disease using the Susceptible/Infected/Recovered (SIR) model.

sphere_ode, an Octave code which sets up the ordinary differential equations (ODE) which model motion on the surface of a sphere.

stiff_ode, an Octave code which considers an ordinary differential equation (ODE) which is an example of a stiff ODE.

two_body_ode, an Octave code which simulates the behavior of two bodies, constrained to lie in a plane, moving under the influence of gravity, with one body much more massive than the other.

zombie_ode, an Octave code which sets up a system of ordinary differential equations (ODE) for a generalized SIR infection model to simulate a zombie attack, developed by Philip Munz.

### Author:

Original MATLAB version by Dominik Gruntz, Joerg Waldvogel.

### Reference:

1. Dominik Gruntz, Joerg Waldvogel,
Orbits in the Planar Three-Body Problem,
Walter Gander, Jiri Hrebicek, editors,
Solving Problems in Scientific Computing using Maple and Matlab,
Springer, 1997,
ISBN: 3-540-61793-0,
LC: Q183.9.G36.