
// Runge-Kutta 6 method with multible differential equations

// dy1/dx=f(x,y1,y2,..,yn)
// dy2/dx=f(x,y1,y2,..,yn)
// ......
// dyn/dx=f(x,y1,y2,..,yn)
// Spring-mass system

import java.io.*;

class fm1 extends f_xi
{
// differential equation of the movement spring-mass system
 double m=2.5;  //kg,
 double k=75.0;   //N/m
 //P(t)= 10*t for t<2s
 //P(t)=20  for t>=2s
 
 double func(double x[],int x_ref )
 {
	double P=0;
	if (x[0]<2.0) {P=10.0*x[0];}
   else if (x[0]>=2.0) {P=20.0;}
   //x[0] is t, x[1] is  ,x[2] is movement amplitude
   if(x_ref==0) return x[2];
    else return (P/m)-(k/m)*x[2];
 }
}

class TNA8_20
{

public static void main(String args[]) throws IOException
{
  fm1 b1=new fm1();
  double y[];
  y=new double[2];
  y[0]=0.0;
  double a[][]=NA93.RK6(b1,0.0,10.0,y,100000);
  int n=a[0].length;
  double amplitude[]=new double[n];
  Plot p1=new Plot(a[0],a[2]);
  p1.addData(a[0],amplitude);
  p1.setXlabel("time");
  p1.setYlabel("amplitude of movement");
  p1.setPlabel("Spring-mass system ");
  p1.plot();
 }
}
