org.opensourcephysics.numerics
Class LeapFrog

java.lang.Object
  extended by org.opensourcephysics.numerics.AbstractODESolver
      extended by org.opensourcephysics.numerics.LeapFrog
All Implemented Interfaces:
ODESolver

public class LeapFrog
extends AbstractODESolver

LeapFrog method ODE solver. The LeapFrog algorithm is a third order algorithm that uses the acceleration to estimate the final position. Note that the velocity plays no part in the integration of the equations. x(n+1) = 2*x(n) - x(n-1) + a(n)*dt*dt v(n+1) = (x(n+1) - x(n-1))/(2 dt) + a(n)*dt The LeapFrog algorithm is equivalent to the velocity Verlet algorithm except that it is not self starting. It is faster than the the velocity Verlet algorithm because it only evaluates the rate once per step. CAUTION! You MUST call the initialize if the state array is changed. The LeapFrog algorithm is not self-starting. The current state and a prior state must both be known to advance the solution. Since the prior state is not known for the initial conditions, a prior state is estimated when the initialize method is invoked. CAUTION! This implementation assumes that the state vector has 2*N + 1 variables. These variables alternate between position and velocity with the last variable being time. That is, the state vector is ordered as follows: x1, d x1/dt, x2, d x2/dt, x3, d x3/dt ..... xN, d xN/dt, t

Version:
1.0
Author:
Wolfgang Christian

Field Summary
 
Fields inherited from class org.opensourcephysics.numerics.AbstractODESolver
numEqn, ode, stepSize
 
Constructor Summary
LeapFrog(ODE ode)
          Constructs the LeapFrog ODESolver for a system of ordinary differential equations.
 
Method Summary
 void initialize(double stepSize)
          Initializes the ODE solver.
 void setStepSize(double stepSize)
          Sets the step size.
 double step()
          Steps (advances) the differential equations by the stepSize.
 
Methods inherited from class org.opensourcephysics.numerics.AbstractODESolver
getStepSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeapFrog

public LeapFrog(ODE ode)
Constructs the LeapFrog 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. Two temporary state arrays and one rate array are allocated. The number of differential equations is determined by invoking getState().length on the ODE.

Specified by:
initialize in interface ODESolver
Overrides:
initialize in class AbstractODESolver
Parameters:
stepSize -

setStepSize

public void setStepSize(double stepSize)
Sets the step size. The step size remains fixed in this algorithm

Specified by:
setStepSize in interface ODESolver
Overrides:
setStepSize in class AbstractODESolver
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
Specified by:
step in class AbstractODESolver
Returns:
the step size