
The general usage idiom is as follows. First begin by writing your own class deriving from DifferentialModel to describe your model, and instantiating an object of this class:
MyDifferentialModel model;
Construct the initial state of the system:
indii::ml::aux::vector y0(4); y0(0) = 1.0; y0(1) = 0.0; y0(2) = 0.0; y0(3) = 2.0;
Create an AdaptiveRungeKutta object, passing in the model to solve and the initial state:
AdaptiveRungeKutta solver(&model, y0);
At this stage setErrorBounds() and setStepSize() may be used to manipulate the Runge-Kutta to be appropriate for the model, balancing speed versus accuracy. The defaults are often sufficient, however.
Now use step() to step through the system. The time step will vary to maintain error bounds, so it is necessary to keep track of the time after each step.
double end = 60.0; double t = 0.0; while (t < end) { t = solver.step(end); std::cout << solver.getState() << std::endl; }
t is guaranteed to reach end at some point, although the number of steps that this will take depends on the model, initial state and error bounds.
If you are only interested in the state of the system at a given time, or wish to use fixed time steps, use stepTo() to jump straight to the required time. Internally, stepTo() essentially just performs the above loop for you, but its use can be more convenient.
For known discontinuities, it is usual to estimate the function piecewise, stepping from start to finish through a continuous piece, then calling setDiscontinuity() before proceeding onto the next.
Definition at line 90 of file AdaptiveRungeKutta.hpp.
Public Member Functions | |
| AdaptiveRungeKutta (DifferentialModel *model) | |
| Constructor. | |
| AdaptiveRungeKutta (DifferentialModel *model, const indii::ml::aux::vector &y0) | |
| Constructor. | |
| virtual | ~AdaptiveRungeKutta () |
| Destructor. | |
| virtual int | calculateDerivativesForward (double t, const double y[], double dydt[]) |
| Calculate derivatives for forwards step. | |
| virtual int | calculateDerivativesBackward (double t, const double y[], double dydt[]) |
| Calculate derivatives for backwards step. | |
| AdaptiveRungeKutta | ( | DifferentialModel * | model | ) |
Constructor.
| model | Model to estimate. |
Definition at line 20 of file AdaptiveRungeKutta.cpp.
| AdaptiveRungeKutta | ( | DifferentialModel * | model, | |
| const indii::ml::aux::vector & | y0 | |||
| ) |
Constructor.
| model | Model to estimate. | |
| y0 | Initial state. |
Definition at line 25 of file AdaptiveRungeKutta.cpp.
| ~AdaptiveRungeKutta | ( | ) | [virtual] |
| int calculateDerivativesForward | ( | double | t, | |
| const double | y[], | |||
| double | dydt[] | |||
| ) | [virtual] |
Calculate derivatives for forwards step.
Implements NumericalSolver.
Definition at line 37 of file AdaptiveRungeKutta.cpp.
| int calculateDerivativesBackward | ( | double | t, | |
| const double | y[], | |||
| double | dydt[] | |||
| ) | [virtual] |
Calculate derivatives for backwards step.
Implements NumericalSolver.
Definition at line 44 of file AdaptiveRungeKutta.cpp.
1.5.3