//======================================================
// 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 fm2 extends f_xi
{

 double func(double x[],int x_ref)
 {
   // Duffing Oscilator
   //  dx/dt=v;
   //  dv/dt=-0.2*v+x-0.1*x^3+cos(t)
   double a=0;
   if(x_ref==1) a=-0.2*x[2]+x[1]-0.1*x[1]*x[1]*x[1]+Math.cos(x[0]);
   else if(x_ref==0) a=x[2];
   return a;
 }
}

class NA101C
{

public static void main(String args[]) throws IOException
{
fm2 b3=new fm2();
  double y[]=new double[2];
  y[0]=0.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,200.0,y,1000000);
  Text.print(Text.T(a));
  Plot pp=new Plot(a[1],a[2]);
  pp.setXlabel("x");
  pp.setYlabel("v velocity");
  pp.setPlabel("Duffing Oscilator ");
  pp.plot();
 }
}
