cnuphys.rk4
Class RungeKutta4

java.lang.Object
  extended by cnuphys.rk4.RungeKutta4
All Implemented Interfaces:
IStepper

public class RungeKutta4
extends java.lang.Object
implements IStepper

A fourth order Runge-Kutta integrator with constant step size..

Author:
heddle

Constructor Summary
RungeKutta4()
          A RungeKutta integrator
 
Method Summary
 void advance(double t, double[] y, double[] dydt, double h, IDerivative deriv, double[] yout)
          Advance the solution by one step of the independent variable.
static void main(java.lang.String[] args)
          Main program for testing.
 int uniformStep(double[] yo, double to, double tf, double[][] y, double[] t, IDerivative deriv, ISwimmer swimmer)
          Driver that uses the RungeKutta advance with a uniform step size.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RungeKutta4

public RungeKutta4()
A RungeKutta integrator

Method Detail

advance

public void advance(double t,
                    double[] y,
                    double[] dydt,
                    double h,
                    IDerivative deriv,
                    double[] yout)
Advance the solution by one step of the independent variable.

Specified by:
advance in interface IStepper
Parameters:
t - the value of the independent variable (usually t) (input).
y - the values of the state vector (usually [x,y,z,vx,vy,vz]) at t (input).
dydt - will be filled with the values of the derivatives at t (input).
h - the current step size (input)
deriv - the function (interface) that can compute the derivatives. That is where the problem specificity resides (input).
yout - where the state vector at the next step will be stored (iutput)

uniformStep

public int uniformStep(double[] yo,
                       double to,
                       double tf,
                       double[][] y,
                       double[] t,
                       IDerivative deriv,
                       ISwimmer swimmer)
Driver that uses the RungeKutta advance with a uniform step size. (I.e., this does NOT use an adaptive step size.) A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.

Parameters:
yo - initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
to - the initial value of the independent variable, e.g., time.
tf - the maximum value of the independent variable.
y - will be filled with results. The first index is small-- the dimensionality of the problem-- i.e., often it is 6 for (xo, yo, zo, vxo, vyo, vzo). The second dimension is for storing results and determining stepsize. If it is 1000, we will have a thousand steps and the stepsize will be (tf-to)/1000 (actually 999).
t - will filled with the locations of t--should have the exact same large dimension as the second index of y--i.e., something like 1000.
derive - the derivative computer (interface). This is where the problem specificity resides.
swimmer - if not null will be used to exit the integration early because some condition has been reached.
Returns:
the number of steps used--may be less than the space provided if the integration ended early as a result of an exit condition.

main

public static void main(java.lang.String[] args)
Main program for testing.

Parameters:
args - command line arguments.