# Parameter Sensitivities with OpenModelica¶

This section describes the use of OpenModelica to compute parameter sensitivities using forward sensitivity analysis together with the Sundials/IDA solver.

*Note: this is a very short preliminary description which soon will be
considerably improved, since this a rather new feature and will
continuous improved.*

*Note: OpenModelica version 1.10 or newer is required.*

## Background¶

Parameter sensitivity analysis aims at analyzing the behavior of the corresponding model states w.r.t. model parameters.

Formally, consider a Modelica model as a DAE system:

where represent state variables, represent state derivatives, represent algebraic variables, model parameters.

For parameter sensitivity analysis the derivatives

are required which quantify, according to their mathematical definition, the impact of parameters on states . In the Sundials/IDA implementation the derivatives are used to evolve the solution over the time by:

## An Example¶

This section demonstrates the usage of the sensitivities analysis in OpenModelica on an example. This module is enabled by the following OpenModelica compiler flag:

```
>>> setCommandLineOptions("--calculateSensitivities");
```

```
model LotkaVolterra
Real x(start=5, fixed=true),y(start=3, fixed=true);
parameter Real mu1=5,mu2=2;
parameter Real lambda1=3,lambda2=1;
equation
0 = x*(mu1-lambda1*y) - der(x);
0 = -y* (mu2 -lambda2*x) - der(y);
end LotkaVolterra;
```

Also for the simulation it is needed to set `IDA`

as solver integration
method and add a further simulation flag `-idaSensitivity`

to calculate
the parameter sensitivities during the normal simulation.

```
>>> simulate(LotkaVolterra, method="ida", simflags="-idaSensitivity")
record SimulationResult
resultFile = "«DOCHOME»/LotkaVolterra_res.mat",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'ida', fileNamePrefix = 'LotkaVolterra', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-idaSensitivity'",
messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
LOG_SUCCESS | info | The simulation finished successfully.
",
timeFrontend = 0.007319258,
timeBackend = 0.004592726,
timeSimCode = 0.067842368,
timeTemplates = 0.035190909,
timeCompile = 0.63631324,
timeSimulation = 0.018638973,
timeTotal = 0.770100096
end SimulationResult;
```

Now all calculated sensitivities are stored into the results mat file under
the $Sensitivities block, where all currently every
**top-level** parameter of the Real type is used to calculate the
sensitivities w.r.t. **every state**.