//======================================================
// 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)
// Changing voltage problem

import java.io.*;


class fm1 extends f_xi
{
 double E0=1.0;  //Volt
 double L=1.0;   // Henry
 double C=0.25;  // Coulomb
 double w2=3.5;  // s^2
 double R=0.0;     // Ohm
 double w=Math.sqrt(w2);
 double p=1.0/Math.sqrt(L*C);
 // Ld^2q/dt^2+R*dq/dt+q/C-E(t)=0
 double func(double x[],int x_ref)
 {
   //x[0] is t, x[1] is q x[2] is i 
   if(x_ref==0) return x[2];
   else  return (-R*x[2]-x[1]/C+E0*Math.sin(w*x[0]))/L;
 }
 double i(double t)
 {
 return -E0/L/(p*p-w2)*w*Math.cos(p*t)+E0/L/(p*p-w2)*w*Math.cos(w*t);	 
 }
 double q(double t)
 {
 return -E0/L/(p*p-w2)*w/p*Math.sin(p*t)+E0/L/(p*p-w2)*Math.sin(w*t);	 
 }
}

class NA98
{

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

  fm1 b1=new fm1();
  double y[];
  y=new double[3];
  y[0]=0.0;
  y[1]=0.0;
  int n=1000000;
  double a[][]=NA93.RK6(b1,0.0,100.0,y,n);
  Plot p1=new Plot(a[0],a[2]);
  double t=0;
  double dt=100.0/n;
  for(int i=0;i<(n-1);i++) {a[1][i]=b1.i(t);t+=dt;}
  p1.addData(a[0],a[1]);
  p1.setXlabel("t time second");
  p1.setYlabel("i=dq/dt Current density Ampere");
  p1.setPlabel("Changing Voltage problem");
  p1.plot();
 }
}
