In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)
plt.rc('font', family='serif')

from __future__ import print_function


from IPython.html.widgets import interact

In [2]:
%%bash 
make
./pythagorean_3body


gfortran -O2 -c physics_pythagorean.f08
gfortran -O2 -c ../bulirsch_stoer.f08 
gfortran -O2 -o pythagorean_3body  physics_pythagorean.f08 ../bulirsch_stoer.f08 pythagorean_3body.f08
 energy (initial): 
  -12.8166666666666666666666666666666665      
 angular momentum (initial): 
   0.00000000000000000000000000000000000      
 
 energy (final): 
  -12.8166666451447610855799440462249786      
 angular momentum (final): 
  -1.26098165773794255814486063720035518E-0010
 overall conservation:
 energy err:
   1.67921239904447770770676368402291641E-0009
 angular momentum err:
   1.26098165773794255814486063720035518E-0010

In [3]:
body_1_filename = 'body_001.dat'
body_2_filename = 'body_002.dat'
body_3_filename = 'body_003.dat'

t_1, x_1, y_1, z_1 = np.loadtxt(body_1_filename, unpack=True, skiprows=1)
t_2, x_2, y_2, z_2 = np.loadtxt(body_2_filename, unpack=True, skiprows=1)
t_3, x_3, y_3, z_3 = np.loadtxt(body_3_filename, unpack=True, skiprows=1)

plot_step_size = 10
def plot_solution(plot_start=40):
    print("plot range: t= ",plot_start,  " - ", plot_start + plot_step_size)

    indices = np.where( ((t_1 > plot_start) & (t_1 < plot_start + plot_step_size)))
    plt.plot(x_1[indices], y_1[indices], linestyle='-')
    plt.plot(x_2[indices], y_2[indices], linestyle='dotted')
    plt.plot(x_3[indices], y_3[indices], linestyle='--')
    plt.xlabel(r"x")
    plt.ylabel(r"y")
    
    plt.legend((r"Body 1", r"Body 2", r"Body 3"))
    
    return

interact(plot_solution, plot_start=(0,60,plot_step_size));


plot range: t=  40  -  50