//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// Runge-Kutta_verner 16 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)
// Van der Pol equation
// hard bit differential equatin model

import java.io.*;


class fm1 extends f_xi
{
//Van der Pol equation
//simulates hard beats
 double mu=1.0;
 // d^2y/dt^2+mu(y^2-1)dy/dt=0
 double func(double x[],int x_ref)
 {
   //x[0] is x, x[1] is y
   if(x_ref==0) return x[2];
   else  return -x[1]-mu*(x[1]*x[1]-1.0)*x[2];
 }
}

class NA97
{


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

  fm1 b1=new fm1();
  double y[];
  y=new double[3];
  y[0]=5;
  y[1]=2.0;
  double a[][]=NA92F.RKV16(b1,0.0,40.0,y,10000);
  Plot p1=new Plot(a[1],a[2]);
  p1.setXlabel("y");
  p1.setYlabel("dy/dt");
  p1.setPlabel("van der Pol equation");
  p1.plot();
  Plot p2=new Plot(a[0],a[1]);
  p2.setXlabel("t");
  p2.setYlabel("y");
  p2.setPlabel("van der Pol equation");
  p2.plot();
 }
}
