//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import java.io.*;

class fm1 extends f_xi
{
//Duffing equation 
 double b=0.08;
 double w02=-1.0;
 double w=1;
 double beta=0.1;
 double f=0.2;
 // d^2y/dt^2+b*dy/dt+w^2*y+beta*y^3=f*cos(w*t)
 double func(double x[],int x_ref)
 {
   //x[0] is t, x[1] is y
   if(x_ref==0) return x[2];
   else  return f*Math.cos(w*x[0])-b*x[2]-w02*x[1]-beta*x[1]*x[1]*x[1];
 }
}

class NA98B
{

public static void main(String args[]) throws IOException
  {

  fm1 b1=new fm1();
  double y[];
  y=new double[3];
  y[0]=-0.8;
  y[1]=0.0;
  double a[][]=NA92F.RKV16(b1,0.0,100.0,y,100000);
  Plot p1=new Plot(a[1],a[2]);
  p1.setXlabel("y");
  p1.setYlabel("dy/dt");
  p1.setPlabel("Duffing equation");
  p1.plot();
  Plot p2=new Plot(a[0],a[2]);
  p2.setXlabel("t");
  p2.setYlabel("y");
  p2.setPlabel("Duffing equation");
  p2.plot();
 }
}

