//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// Runge-Kutta 6 method with multible differential equations
// Dr. Turhan Coban
// =====================================================
// dy1/dx=f(x,y1,y2,..,yn)
// dy2/dx=f(x,y1,y2,..,yn)
// ......
// dyn/dx=f(x,y1,y2,..,yn)
// Pendulum problem

import java.io.*;

class fm extends f_xi
{ double m,n;
 public fm(double mi,double ni)
 {m=mi;n=ni;}
 double func(double x[],int x_ref)
 {
   //  Three celestial body problem 
   double a=0;
   if(x_ref==3) a= -x[3]-m*x[2]/Math.pow(((x[1]+n)*(x[1]+n)+x[2]*x[2]),1.5)-n*x[2]/Math.pow(((x[1]-m)*(x[1]-m)+x[2]*x[2]),1.5);
   else if(x_ref==2) a= x[4]-m*(x[1]+n)/Math.pow(((x[1]+n)*(x[1]+n)+x[2]*x[2]),1.5)-n*(x[1]-m)/Math.pow(((x[1]-m)*(x[1]-m)+x[2]*x[2]),1.5);
   else if(x_ref==1) a= x[4]-x[1];
   else if(x_ref==0) a= x[3]+x[2];
   return a;
 }
}

class NA101F
{

public static void main(String args[]) throws IOException
{
fm b3=new fm(0.98,0.02);
  double y[]=new double[4];
  y[0]=0.44;
  y[1]=0.866; 
  y[2]=-0.866;
  y[3]=0.48; 
  //solution of the differential system : 
  double xi[]=new double[20];
  double fi[]=new double[20];
  double a[][];
  a=NA93.RK6(b3,0.0,500.0,y,1000000);
  //Text.print(Text.T(a));1
  Plot pp=new Plot(a[1],a[2]);
  pp.setXlabel("x");
  pp.setYlabel("y");
  pp.setPlabel("3 celestial body problem ");
  pp.plot();
 }
}
