integrators
Class MidpointIntegrator

java.lang.Object
  extended byintegrators.Integrator
      extended byintegrators.MidpointIntegrator

public class MidpointIntegrator
extends Integrator

Modified Midpoint Method as described in Numerical Recipes in C; this is NOT a translation of their code (which I didn't even look at), but merely my implementation of the recipe outlined in the text. This should be used as a subsidiary of an Bulirsch-Stoer-type Integrator, but can also be used as an integrator in it own right, although since I have a hard time imagining why anyone would do so, the error control implemented here is rudimentary and inefficient. The goal of this approach is to cross a large interval H with a series of n substeps h. The first substep is a forward Euler step. Subsequent steps are midpoint estimates with y(t+h) = y(t-h) + 2hf(y(t)). The final step averages the first estimate of y(t+nh) with a backward Euler step from y(t+(n-1)h). Calling MidpointIntegrator.IntegrateOneStep(int n) causes the Integrator to cross the interval set by its timestep using n substeps. This is the call to make if the MidpointIntegrater is being used as a susidiary method. The generic IntegrateOneStep() method, on the other hand, allows one to use this method in its own right according to a formula in NRC (see comment in MidpointIntegrator.IntegrateOneStep()).


Nested Class Summary
 
Nested classes inherited from class integrators.Integrator
Integrator.NVmatrix, Integrator.NVvector
 
Constructor Summary
MidpointIntegrator()
          no-argument constructor allows instantiating a MidpointIntegrator generically from its name alone, with default number of substeps = 8.
 
Method Summary
 void init(Model model)
          init() allocates the necessary storage, nothing else.
 float IntegrateOneStep()
          Call IntegrateOneStep() to use the Modified Midpoint Method by itself; this call uses an estimate give in NRC based on a weighted sum of results from crossing the interval with n/2 substeps and then with n substeps...
 float IntegrateOneStep(int num_substeps)
          Call IntegrateOneStep(int) with the desired number of substeps as the argument when using the Modified Midpoint Method as part of another method, like the BulirschStoerIntegrator.
 void setNumberOfSubsteps(int n)
          If one is going to use this object as an integrator in its own right, rather than as a subsidiary of a more sophisticate one, then one has the option of setting how many substeps it uses to cross an interval.
 
Methods inherited from class integrators.Integrator
copyNVarray, getCurrentValues, getDerivatives, getErrorEstimate, isType, reset, setDefaultStepSize, setErrorTolerance, setFinalValues, setIntegrationValues, setStepSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MidpointIntegrator

public MidpointIntegrator()
no-argument constructor allows instantiating a MidpointIntegrator generically from its name alone, with default number of substeps = 8.

Method Detail

init

public void init(Model model)
init() allocates the necessary storage, nothing else.

Overrides:
init in class Integrator

IntegrateOneStep

public float IntegrateOneStep()
Call IntegrateOneStep() to use the Modified Midpoint Method by itself; this call uses an estimate give in NRC based on a weighted sum of results from crossing the interval with n/2 substeps and then with n substeps... use MidpointIntegrator.setNumberOfSubSteps(int) to set n; yEst = (4/3)yEst(n) - (1/3)yEst(n/2). The error is the maximum one-dimensional difference between the coarse estimate and finer one with all n substeps. Probably not the most useful estimate in the world, but I haven't thought of a better one, and I probably won't because I don't intend to use this method on its own. The rudimentary error control here seems very inefficient.

Overrides:
IntegrateOneStep in class Integrator

IntegrateOneStep

public float IntegrateOneStep(int num_substeps)
Call IntegrateOneStep(int) with the desired number of substeps as the argument when using the Modified Midpoint Method as part of another method, like the BulirschStoerIntegrator. Keep in mind that the result is actually copied into the Model's Nodes, so copy the current state before calling this method to get an estimate of the next state, then restore it from the copy before trying to get another estimate! Also note that this call does NOT make any estimate of the error per timestep, so calls to getErrorEstimate() will return a meaningless value


setNumberOfSubsteps

public void setNumberOfSubsteps(int n)
If one is going to use this object as an integrator in its own right, rather than as a subsidiary of a more sophisticate one, then one has the option of setting how many substeps it uses to cross an interval. The default is 8.