org.opensourcephysics.numerics
Class CashKarp45

java.lang.Object
  extended by org.opensourcephysics.numerics.CashKarp45
All Implemented Interfaces:
ODEAdaptiveSolver, ODESolver

public class CashKarp45
extends java.lang.Object
implements ODEAdaptiveSolver

CashKarp45 implements a RKF 4/5 ODE solver with variable step size using Cash-Karp coefficients.

Version:
1.0
Author:
W. Christian, F. Esquembre

Field Summary
protected  boolean enableExceptions
           
protected  double tol
           
 
Fields inherited from interface org.opensourcephysics.numerics.ODEAdaptiveSolver
BISECTION_EVENT_NOT_FOUND, DID_NOT_CONVERGE, NO_ERROR
 
Constructor Summary
CashKarp45(ODE _ode)
          Constructs the CashKarp45 ODESolver for a system of ordinary differential equations.
 
Method Summary
 void enableRuntimeExpecptions(boolean enable)
          Enables runtime exceptions if the solver does not converge.
 int getErrorCode()
          Gets the error code.
 double getStepSize()
          Gets the step size.
 double getTolerance()
          Method getTolerance
 void initialize(double _stepSize)
          Initializes the ODE solver.
 void setStepSize(double stepSize)
          Sets the step size.
 void setTolerance(double _tol)
          Method setTolerance
 double step()
          Steps (advances) the differential equations by the stepSize.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tol

protected double tol

enableExceptions

protected boolean enableExceptions
Constructor Detail

CashKarp45

public CashKarp45(ODE _ode)
Constructs the CashKarp45 ODESolver for a system of ordinary differential equations.

Parameters:
_ode - the system of differential equations.
Method Detail

initialize

public void initialize(double _stepSize)
Initializes the ODE solver. Temporary state and rate arrays are allocated. The number of differential equations is determined by invoking getState().length on the ODE.

Specified by:
initialize in interface ODESolver
Parameters:
_stepSize -

step

public double step()
Steps (advances) the differential equations by the stepSize. The ODESolver invokes the ODE's getRate method to obtain the initial state of the system. The ODESolver then advances the solution and copies the new state into the state array at the end of the solution step.

Specified by:
step in interface ODESolver
Returns:
the step size

enableRuntimeExpecptions

public void enableRuntimeExpecptions(boolean enable)
Enables runtime exceptions if the solver does not converge.

Parameters:
enable - boolean

setStepSize

public void setStepSize(double stepSize)
Sets the step size. The step size may change when the step method is invoked.

Specified by:
setStepSize in interface ODESolver
Parameters:
stepSize -

getStepSize

public double getStepSize()
Gets the step size. The stepsize is adaptive and may change as the step() method is invoked.

Specified by:
getStepSize in interface ODESolver
Returns:
the step size

setTolerance

public void setTolerance(double _tol)
Method setTolerance

Specified by:
setTolerance in interface ODEAdaptiveSolver
Parameters:
_tol -

getTolerance

public double getTolerance()
Method getTolerance

Specified by:
getTolerance in interface ODEAdaptiveSolver
Returns:
tolerance

getErrorCode

public int getErrorCode()
Gets the error code. Error codes: ODEAdaptiveSolver.NO_ERROR ODEAdaptiveSolver.DID_NOT_CONVERGE

Specified by:
getErrorCode in interface ODEAdaptiveSolver
Returns:
int