//======================================================
// 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 m;
 double kd;
 double ks;
	public fm1(double mi,double kdi,double ksi)
    {m=mi;kd=kdi;ks=ksi;}
    public double P(double t)
    {
	//Force effecting on system
	double p=0;
	if(t<2) p=10*t;
	else p=0;
	return p;
	}
 // shock absorber-spring system
 double func(double x[],int x_ref)
 {
   //x[0] is t, x[1] is x, x[2] is dx/dt
   if(x_ref==0) return x[2];
   else if(x_ref==1) return P(x[0])/m-x[2]*kd/m-x[1]*ks/m;
   else return 0;
 }
}

class NA102
{

public static void main(String args[]) throws IOException
  {
  fm1 b1=new fm1(5.0,33.0,500.0);
  double y[];
  y=new double[2];
  y[0]=0.0;
  y[1]=0.0;
  double a[][]=NA93.RK6(b1,0.0,5.0,y,1000);
  //System.out.println(Matrix.toString(a));
  Plot p1=new Plot(a[0],a[1]);
  p1.setXlabel("t second");
  p1.setYlabel("X displacement");
  p1.setPlabel("Shock absorber m = "+b1.m+" Shock kd = "+b1.kd+"N/m Spring ks= "+b1.ks+"N/m");
  //p1.setMinMax(0,2,0,200);
  p1.plot();
 }
}
