//======================================================
// 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 r,w02,b,f,w;
 public fm(double ri,double w02i,double bi,double fi,double wi)
 {r=ri;w02=w02i;b=bi;f=fi;w=wi;}
 double func(double x[],int x_ref)
 {
   double a=0;
   if(x_ref==1) a= f*Math.cos(w*x[0])-r*x[2]-w02*x[1]-b*x[1]*x[1]*x[1];
   else if(x_ref==0) a= x[2];
   return a;
 }
}

class NA101G
{

public static void main(String args[]) throws IOException
{
  fm b3=new fm(0.2,1.0,1.0,16.5,1.0);
  double y[]=new double[4];
  y[0]=1.0;
  y[1]=0.0;  
  //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("v=dx/dt");
  pp.setPlabel("Duffling oscilator ");
  pp.plot();
 }
}
