JMSLTM Numerical Library 4.0

com.imsl.math
Class OdeRungeKutta

java.lang.Object
  extended bycom.imsl.math.OdeRungeKutta
All Implemented Interfaces:
Cloneable, Serializable

public class OdeRungeKutta
extends Object
implements Serializable, Cloneable

Solves an initial-value problem for ordinary differential equations using the Runge-Kutta-Verner fifth-order and sixth-order method.

Class OdeRungeKutta finds an approximation to the solution of a system of first-order differential equations of the form y_0 = f (t, y) with given initial data. The routine attempts to keep the global error proportional to a user-specified tolerance. This routine is efficient for nonstiff systems where the derivative evaluations are not expensive.

OdeRungeKutta is based on a code designed by Hull, Enright and Jackson (1976, 1977). It uses Runge-Kutta formulas of order five and six developed by J. H. Verner.

See Also:
Example, Serialized Form

Nested Class Summary
static class OdeRungeKutta.DidNotConvergeException
          The iteration did not converge.
static interface OdeRungeKutta.Function
          Public interface for user supplied function to OdeRungeKutta object.
static class OdeRungeKutta.ToleranceTooSmallException
          Tolerance is too small.
 
Field Summary
static int AFTER_SUCCESSFUL_STEP
          Used by method examineStep to indicate examining after a successful step
static int AFTER_UNSUCCESSFUL_STEP
          Used by method examineStep to indicate examining after an unsuccessful step
static int BEFORE_STEP
          Used by method examineStep to indicate examining before the next step
 
Constructor Summary
OdeRungeKutta(OdeRungeKutta.Function function)
          Constructs an ODE solver to solve the initial value problem dy/dx = f(x,y)
 
Method Summary
protected  void examineStep(int state, double x, double[] y)
          Called before and after each internal step.
 void setFloor(double floor)
          Sets the value used in the norm computation.
 void setInitialStepsize(double stepsize)
          Sets the initial internal step size.
 void setMaximumStepsize(double stepsize)
          Sets the maximum internal step size.
 void setMaxSteps(int maxSteps)
          Sets the maximum number of internal steps allowed.
 void setMinimumStepsize(double stepsize)
          Sets the minimum internal step size.
 void setNorm(int normMethod)
          Sets the switch for determining the error norm.
 void setScale(double scale)
          Sets the scaling factor.
 void setTolerance(double tolerance)
          Sets the error tolerance.
 void solve(double x, double xEnd, double[] y)
          Integrates the ODE system from x to xEnd.
protected  double vnorm(double[] v, double[] y, double[] ymax)
          Returns the norm of a vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AFTER_SUCCESSFUL_STEP

public static final int AFTER_SUCCESSFUL_STEP
Used by method examineStep to indicate examining after a successful step

See Also:
Constant Field Values

AFTER_UNSUCCESSFUL_STEP

public static final int AFTER_UNSUCCESSFUL_STEP
Used by method examineStep to indicate examining after an unsuccessful step

See Also:
Constant Field Values

BEFORE_STEP

public static final int BEFORE_STEP
Used by method examineStep to indicate examining before the next step

See Also:
Constant Field Values
Constructor Detail

OdeRungeKutta

public OdeRungeKutta(OdeRungeKutta.Function function)
Constructs an ODE solver to solve the initial value problem dy/dx = f(x,y)

Parameters:
function - Implementation of interface Function that defines the right-hand side function f(x,y)
Method Detail

examineStep

protected void examineStep(int state,
                           double x,
                           double[] y)
Called before and after each internal step.

Parameters:
state - an int, one of BEFORE_STEP, AFTER_SUCCESSFUL_STEP or AFTER_UNSUCCESSFUL_STEP.
x - double representing the indepenent variable.
y - double array containing the dependent variables.

setFloor

public void setFloor(double floor)
Sets the value used in the norm computation.

Parameters:
floor - double used in the norm computation, default value is 1.
Throws:
IllegalArgumentException - is thrown if floor is less than or equal to zero.

setInitialStepsize

public void setInitialStepsize(double stepsize)
Sets the initial internal step size.

Parameters:
stepsize - double specifying the initial internal step size.
Throws:
IllegalArgumentException - is thrown if stepsize is less than or equal to zero.

setMaximumStepsize

public void setMaximumStepsize(double stepsize)
Sets the maximum internal step size.

Parameters:
stepsize - Maximum internal step size. Default value is 2.
Throws:
IllegalArgumentException - is thrown if stepsize is less than or equal to 0.

setMaxSteps

public void setMaxSteps(int maxSteps)
Sets the maximum number of internal steps allowed.

Parameters:
maxSteps - int specifying the maximum number of internal steps allowed, default value is 500
Throws:
IllegalArgumentException - is thrown if maxSteps is less than or equal to zero.

setMinimumStepsize

public void setMinimumStepsize(double stepsize)
Sets the minimum internal step size.

Parameters:
stepsize - Minimum internal step size. Default value is 0.
Throws:
IllegalArgumentException - is thrown if stepsize is less than or equal to 0.

setNorm

public void setNorm(int normMethod)
Sets the switch for determining the error norm.

Parameters:
normMethod - int specifying the switch for determining the error norm, default value is 0. In the following, e_i is the absolute value fo an estimate of the error in y_i(t)

norm Constraint
0 Minimum of the absolute error and the relative error, equals the maximum of e_i/max(|y_i(t)|, 1)
1 Absolute error, equals max(e_i)
2 Maximum of e_i/max(|y_i(t)|, floor)

Throws:
IllegalArgumentException - is thrown if norm is is not 0, 1, or 2.

setScale

public void setScale(double scale)
Sets the scaling factor.

Parameters:
scale - double specifying the scaling factor, default value is 1.e0
Throws:
IllegalArgumentException - is thrown if scale is less than or equal to 0.

setTolerance

public void setTolerance(double tolerance)
Sets the error tolerance.

Parameters:
tolerance - double specifying the error tolerance. Default value is 1.0e-6.
Throws:
IllegalArgumentException - is thrown if tolerance less than or equal 0.

solve

public void solve(double x,
                  double xEnd,
                  double[] y)
           throws OdeRungeKutta.ToleranceTooSmallException,
                  OdeRungeKutta.DidNotConvergeException
Integrates the ODE system from x to xEnd. On all but the first call to solve, the value of x must equal the value of xEnd for the previous call.

Parameters:
x - double specifying the independent variable
xEnd - double specifying the value of x at which the solution is desired
y - On input, double array containing the initial values. On output, double array containing the approximate solution.
Throws:
OdeRungeKutta.DidNotConvergeException - is thrown if the number of internal steps exceeds maxSteps (default 500). This can be an indication that the ODE system is stiff. This exception can also be thrown if the error tolerance condition could not be met.
OdeRungeKutta.ToleranceTooSmallException - is thrown if the computation does not converge on some step.

vnorm

protected double vnorm(double[] v,
                       double[] y,
                       double[] ymax)
Returns the norm of a vector.

Parameters:
v - double array containing the vector whose norm is to be computed
y - double array containing the values of the dependent variable
ymax - double array containing the maximum y values computed thus far
Returns:
double scalar value representing the norm of the vector v

JMSLTM Numerical Library 4.0

Copyright 1970-2006 Visual Numerics, Inc.
Built June 1 2006.