import java.util.*;
//***********************************************************************************


//***********************************************************************************

public class ChuaFunction extends OdesFunction {
      
      private static final double Pi2=2*Math.PI;
      double f=0;
      double resRatio=0.636;
      
      ChuaFunction(int n) {
            super(n);
            x0=new double[n];
            x0[0]=0.;
            x0[1]=0.1;
            x0[2]=0.15;
            x0[3]=0.05;
            dt=1.0;
            trans=50.;
            ghostTime=50.;
            poincareSection=3.14;
            title="Chua Circuit";
            nParameters=4;
            aDefault=new double[nParameters];
            aDefault[0]=0.923;
            aDefault[1]=0.066;
            aDefault[2]=0.779;
            aDefault[3]=0.071;
            a=new double[nParameters];                 
            
      }      
      
//***********************************************************************************
/** Sets the equation paramters 
* @param paramters the array of input paramters
*/
//***********************************************************************************      
      public void setParameters(double[] parameters) {
            for(int i=0; i<nParameters;i++) a[i]=parameters[i];
      }

//*********************************************************************
/**
* Returns RHS of differential equations for Lorenz model
* @param x[] vector of current value of dependent variables
* @param n number of dependent variables in array x[]
* @param t current value of independent variable
* @return n component vector giving derivatives of dependent variables
*/
//*********************************************************************       
      public double[] derivs(double[] x, double t){
           double rhs[] = new double[nVariables];
           rhs[0]=1.;
           if(x[1]<=1. && x[1] >= -1.) f=-x[1];
           else if(x[1]>10.) f=10.*(x[1]-10.)-9.*resRatio-1.;
           else if(x[1]>1.) f=-resRatio*x[1]-1.+resRatio;
           else if(x[1]<-10.)f=10.*(x[1]+10.)+9.*resRatio+1. ;
           else if(x[1]<-1.)f=-resRatio*x[1]+1.-resRatio;                                              
           else System.out.println("Error in derivs");
           rhs[0]=1.;
           rhs[1]=a[0]*(x[2]-x[1])-f;
           rhs[2]=a[1]*(a[0]*(x[1]-x[2])+x[3]);
           rhs[3]=-a[2]*(x[2]+a[3]*x[3]);     
           return rhs;
      }

     
//***********************************************************************************
/** Returnd the number of paraemters defining the map
* @return number of parameters
*/
//***********************************************************************************
     public int getNParameters() {
            return nParameters;
     } 
                  
}
