//======================================================
// 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)
// Gun fire bullet trajectory with air friction
import java.io.*;


class fm1 extends f_xi
{
 double gamma;
	public fm1(double gammai)
    {gamma=gammai;}
 // gun shot with friction
 double func(double x[],int x_ref)
 {
   //x[1] is x, x[2] is y
   double g=9.806;
   if(x_ref==0) return x[3];
   else if(x_ref==1) return x[4];
   else if(x_ref==2) return -gamma*Math.sqrt(x[3]*x[3]+x[4]*x[4])*x[3];
   else              return -g - gamma*Math.sqrt(x[3]*x[3]+x[4]*x[4])*x[4];
 }
}

class NA100
{

public static void main(String args[]) throws IOException
  {
  fm1 b1=new fm1(0.001);
  double y[];
  y=new double[4];
  double V0=250.0;//  m/s
  double alfa=Math.PI/3; //60 degree
  y[0]=0.0;
  y[1]=0.0;
  y[2]=V0*Math.cos(alfa);
  y[3]=V0*Math.sin(alfa);
  double a[][]=NA93.RK6(b1,0.0,100.0,y,5000);
  Plot p1=new Plot(a[1],a[2]);
  alfa=Math.PI/4;  //45 degree
  y[2]=V0*Math.cos(alfa);
  y[3]=V0*Math.sin(alfa);
  double b[][]=NA93.RK6(b1,0.0,100.0,y,5000);
  p1.addData(b[1],b[2]);
  alfa=Math.PI/6;  //30 degree
  y[2]=V0*Math.cos(alfa);
  y[3]=V0*Math.sin(alfa);
  double c[][]=NA93.RK6(b1,0.0,100.0,y,5000);
  p1.addData(c[1],c[2]);
  double xa[]=new double[2];
  double ya[]=new double[2];
  xa[0]=0;xa[1]=12.0;
  ya[0]=0;ya[1]=0.0;
  p1.addData(xa,ya);
  p1.setXlabel("x");
  p1.setYlabel("y");
  p1.setPlabel("Gun fire bullet trajectory with air friction 60,45 ve 30 degree \n starting angle and 250 m/s starting velocity");
  p1.setMinMax(0,1500,0,1500);
  p1.plot();
 }
}
