nr.ode
Class ODE

java.lang.Object
  extended by nr.ode.ODE

public abstract class ODE
extends java.lang.Object

solves one step of an Ordinal Differential Equation. The constructor takes a vector function that returns dx/dt for a given x (note the notation here is different from Numerical Recipes chapter 16, which uses dy/dx as a function of x. The solver also takes a desired accuracy, epsilon. The interpretation of epsilon is entirely dependent on the implementation of this abstract class

Each call to the method solve(x,h) updates the vector x with the new values time h later.

Assumes dx/dt is independent of t (is a function only of x). If dxd/t is time-dependent, add a new variable to x with x[n] = start time on input and dxdt[n] = 1 always. *

Author:
Daniel Wachsstock

Nested Class Summary
static class ODE.Factory
          an ODE factory that allows changing the algorithm.
 
Field Summary
static int MAX_ITERATIONS
           
 
Constructor Summary
ODE(VecFunction dxdt)
          Creates a new instance of ODE
 
Method Summary
static java.lang.String description()
          a description of this ODE solving algorithm, for selection and display.
 double getEpsilon()
          return the relative accuracy parameter
 double maxRatio(Vec numer, Vec denom, double max)
          utility method to calculate the maximum ratio of elements of two arrays.
static java.lang.String name()
          the name of this ODE solving algorithm, for selection and display.
 void setEpsilon(double epsilon)
          set the desired relative accuracy parameter.
 void solve(Vec x, double endT)
          solve the ODE starting from x at time 0 to time endT, updating x
 void solve(Vec x, double[] h)
          solve the ODE starting from x at time 0 to time less than or equal (in absolute value) to endT, updating x
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ITERATIONS

public static final int MAX_ITERATIONS
See Also:
Constant Field Values
Constructor Detail

ODE

public ODE(VecFunction dxdt)
Creates a new instance of ODE

Parameters:
dxdt - the VecFunction that describes this ode
Method Detail

setEpsilon

public void setEpsilon(double epsilon)
set the desired relative accuracy parameter. Each implementation decides how to interpret this, if at all


getEpsilon

public double getEpsilon()
return the relative accuracy parameter


solve

public void solve(Vec x,
                  double endT)
           throws DidNotConvergeException
solve the ODE starting from x at time 0 to time endT, updating x

Parameters:
x - the starting vector. On return, the ending vector
endT - the ending time. endT is allowed to be negative.
Throws:
DidNotConvergeException - if the solver could not converge on a solution

solve

public void solve(Vec x,
                  double[] h)
           throws DidNotConvergeException
solve the ODE starting from x at time 0 to time less than or equal (in absolute value) to endT, updating x

Parameters:
x - the starting vector. On return, the ending vector.
h - a two-element array. h[0] is the stepsize to try initially, and h[1] is the maximum stepsize. This routine may use any step size it wants, up to h[1]. Note that h[0] and h[1] may be negative but both will have the same sign and abs(h[0]) <= abs(h[1]); this is assured by the calling method. On return, h[0] is the predicted ideal step size for the next step and h[1] is the step actually taken
Throws:
DidNotConvergeException - if the solver could not converge on a solution

maxRatio

public double maxRatio(Vec numer,
                       Vec denom,
                       double max)
utility method to calculate the maximum ratio of elements of two arrays.

Parameters:
numer - the vector of numerators
denom - the vector of denominators
max - the minimum value to return.

name

public static java.lang.String name()
the name of this ODE solving algorithm, for selection and display.

Returns:
the name of this ODE algorithm

description

public static java.lang.String description()
a description of this ODE solving algorithm, for selection and display.

Returns:
the description of this ODE algorithm