## Interface SecondaryODE

• All Known Subinterfaces:
`SecondaryEquations`

`public interface SecondaryODE`
This interface allows users to add secondary differential equations to a primary set of differential equations.

In some cases users may need to integrate some problem-specific equations along with a primary set of differential equations. One example is optimal control where adjoined parameters linked to the minimized hamiltonian must be integrated.

This interface allows users to add such equations to a primary set of `first order differential equations` thanks to the `ExpandableODE.addSecondaryEquations(SecondaryODE)` method.

`ExpandableODE`
• ### Method Summary

All Methods
Modifier and Type Method Description
`double[]` ```computeDerivatives​(double t, double[] primary, double[] primaryDot, double[] secondary)```
Compute the derivatives related to the secondary state parameters.
`int` `getDimension()`
Get the dimension of the secondary state parameters.
`default void` ```init​(double t0, double[] primary0, double[] secondary0, double finalTime)```
Initialize equations at the start of an ODE integration.
• ### Method Detail

• #### getDimension

`int getDimension()`
Get the dimension of the secondary state parameters.
Returns:
dimension of the secondary state parameters
• #### init

```default void init​(double t0,
double[] primary0,
double[] secondary0,
double finalTime)```
Initialize equations at the start of an ODE integration.

This method is called once at the start of the integration. It may be used by the equations to initialize some internal data if needed.

The default implementation does nothing.

Parameters:
`t0` - value of the independent time variable at integration start
`primary0` - array containing the value of the primary state vector at integration start
`secondary0` - array containing the value of the secondary state vector at integration start
`finalTime` - target time for the integration
• #### computeDerivatives

```double[] computeDerivatives​(double t,
double[] primary,
double[] primaryDot,
double[] secondary)
throws MathIllegalArgumentException,
MathIllegalStateException```
Compute the derivatives related to the secondary state parameters.

In some cases, additional equations can require to change the derivatives of the primary state (i.e. the content of the `primaryDot` array). One use case is optimal control, when the secondary equations handle co-state, which changes control, and the control changes the primary state. In this case, the primary and secondary equations are not really independent from each other, so if possible it would be better to put state and co-state and their equations all in the primary equations. As this is not always possible, this method explicitly allows to modify the content of the `primaryDot` array. This array will be used to evolve the primary state only after all secondary equations have computed their derivatives, hence allowing this side effect.

Parameters:
`t` - current value of the independent time variable
`primary` - array containing the current value of the primary state vector
`primaryDot` - array containing the derivative of the primary state vector (the method is allowed to change the derivatives here, when the additional equations do have an effect on the primary equations)
`secondary` - array containing the current value of the secondary state vector
Returns:
derivative of the secondary state vector
Throws:
`MathIllegalStateException` - if the number of functions evaluations is exceeded
`MathIllegalArgumentException` - if arrays dimensions do not match equations settings