|
JMSLTM Numerical Library 4.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.imsl.math.OdeRungeKutta
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
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.
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 |
public static final int AFTER_SUCCESSFUL_STEP
examineStep
to indicate examining after
a successful step
public static final int AFTER_UNSUCCESSFUL_STEP
examineStep
to indicate examining after
an unsuccessful step
public static final int BEFORE_STEP
examineStep
to indicate examining before
the next step
Constructor Detail |
public OdeRungeKutta(OdeRungeKutta.Function function)
function
- Implementation of interface Function
that defines the right-hand side function
f(x,y)Method Detail |
protected void examineStep(int state, double x, double[] y)
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.public void setFloor(double floor)
floor
- double
used in the norm computation,
default value is 1.
IllegalArgumentException
- is thrown if floor
is less than or equal to zero.public void setInitialStepsize(double stepsize)
stepsize
- double
specifying the initial internal step size.
IllegalArgumentException
- is thrown if stepsize
is less than or equal to zero.public void setMaximumStepsize(double stepsize)
stepsize
- Maximum internal step size.
Default value is 2.
IllegalArgumentException
- is thrown if stepsize
is less than or equal to 0.public void setMaxSteps(int maxSteps)
maxSteps
- int
specifying the maximum number of internal
steps allowed, default value is 500
IllegalArgumentException
- is thrown if maxSteps
is less than or equal to zero.public void setMinimumStepsize(double stepsize)
stepsize
- Minimum internal step size.
Default value is 0.
IllegalArgumentException
- is thrown if stepsize
is less than or equal to 0.public void setNorm(int normMethod)
normMethod
- int
specifying the switch for determining
the error norm, default value is 0.
In the following, is the absolute
value fo an estimate of the error in
norm | Constraint |
0 | Minimum of the absolute error and the relative error, equals the maximum of |
1 | Absolute error, equals |
2 | Maximum of |
IllegalArgumentException
- is thrown if norm
is is not 0, 1, or 2.public void setScale(double scale)
scale
- double
specifying the scaling factor,
default value is 1.e0
IllegalArgumentException
- is thrown if scale
is less than or equal to 0.public void setTolerance(double tolerance)
tolerance
- double
specifying the error tolerance.
Default value is 1.0e-6.
IllegalArgumentException
- is thrown if tolerance
less than or equal 0.public void solve(double x, double xEnd, double[] y) throws OdeRungeKutta.ToleranceTooSmallException, OdeRungeKutta.DidNotConvergeException
x
- double
specifying the independent variablexEnd
- double
specifying the value of x at which the
solution is desiredy
- On input, double
array containing the initial values.
On output, double
array containing the approximate solution.
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.protected double vnorm(double[] v, double[] y, double[] ymax)
v
- double
array containing the vector whose
norm is to be computedy
- double
array containing the values of the
dependent variableymax
- double
array containing the maximum y values
computed thus far
double
scalar value representing the norm of
the vector v
|
JMSLTM Numerical Library 4.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |