//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// Runge-Kutta-Verner 16 constant step 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)
// LORENTS equation solution
import java.io.*;

class fm2 extends f_xi
{
//multivariable function
double sigma=10.0;
 double lambda=22.0;
 double gamma=1.0;

 double func(double x[],int x_ref)
 {
   //x[0] is x, x[1] is y

   if(x_ref==0) return sigma*(x[2]-x[1]);
   if(x_ref==1) return (1+lambda-x[3])*x[1]-x[2];
   else         return x[1]*x[2]-gamma*x[3];
 }
}

class NA95
{

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

  fm2 b1=new fm2();
  double y[];
  y=new double[3];
  y[0]=1.0;
  y[1]=1.0;
  y[2]=20.0;
  double a[][]=NA92F.RKV16(b1,0.0,40.0,y,10000);
  Plot p1=new Plot(a[1],a[3]);
  p1.setXlabel("x1");
  p1.setYlabel("x3");
  p1.setPlabel("Lorentz attractor");
  p1.plot();
  Plot p2=new Plot(a[0],a[1]);
  p2.setXlabel("x0");
  p2.setYlabel("x3");
  p2.setPlabel("Lorentz equation");
  p2.plot();
 }
}
