//======================================================
// 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)
// Lotka - Volterra equation
// Preditor-Prey model
import java.io.*;

class fm1 extends f_xi
{
//Preditor-Prey model
// Lotka-Volterra equation
 double a=1.2;  //prey birth rate
 double b=0.6;  //preditor death rate
 double c=0.8;  //effect of preditor-prey relation on prey death rate 
 double d=0.5;  //effect of preditor-prey relations on preditor birth rate

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

   if(x_ref==0) return a*x[1]-b*x[1]*x[2];
   else return -c*x[2]+d*x[1]*x[2];
 }
}

class NA96
{

public static void main(String args[]) throws IOException
{
  fm1 b1=new fm1();
  double y[];
  y=new double[2];
  y[0]=1.0;
  y[1]=2.0;
  double a[][]=NA92F.RKV16(b1,0.0,40.0,y,10000);
  Plot p1=new Plot(a[0],a[1]);
  p1.addData(a[0],a[2]);
  p1.setXlabel("time");
  p1.setYlabel("Predator and Prey population");
  p1.setPlabel("Predator-Prey model");
  p1.plot();
  
  Plot p2=new Plot(a[1],a[2]);
  p2.setXlabel("Prey");
  p2.setYlabel("Predator");
  p2.setPlabel("Predator-Prey model");
  p2.plot();
 }
}
