---
title: "SystemModelCalibrate"
language: "en"
type: "Symbol"
summary: "SystemModelCalibrate[data, smodel, pars] calibrates the parameters pars in the system model smodel according to data. SystemModelCalibrate[data, {smodel, cons}, pars] calibrates the parameters pars subject to the constraints cons. SystemModelCalibrate[..., spec] calibrates following the specification spec. SystemModelCalibrate[...,  prop] gives the value of the property  prop."
keywords: 
- model identification
- model fitting
- model training
- digital twin
- model calibration
- calibrating a model
canonical_url: "https://reference.wolfram.com/language/ref/SystemModelCalibrate.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "System Model Creation"
    link: "https://reference.wolfram.com/language/guide/SystemModelCreation.en.md"
  - 
    title: "System Modeling Overview"
    link: "https://reference.wolfram.com/language/guide/SystemModelingOverview.en.md"
related_functions: 
  - 
    title: "SystemModelSimulationData"
    link: "https://reference.wolfram.com/language/ref/SystemModelSimulationData.en.md"
  - 
    title: "SystemModelExamples"
    link: "https://reference.wolfram.com/language/ref/SystemModelExamples.en.md"
  - 
    title: "SystemModel"
    link: "https://reference.wolfram.com/language/ref/SystemModel.en.md"
  - 
    title: "SystemModelSimulateSensitivity"
    link: "https://reference.wolfram.com/language/ref/SystemModelSimulateSensitivity.en.md"
  - 
    title: "SystemModelPlot"
    link: "https://reference.wolfram.com/language/ref/SystemModelPlot.en.md"
  - 
    title: "SystemModelParametricSimulate"
    link: "https://reference.wolfram.com/language/ref/SystemModelParametricSimulate.en.md"
  - 
    title: "NDSolveValue"
    link: "https://reference.wolfram.com/language/ref/NDSolveValue.en.md"
  - 
    title: "DSolveValue"
    link: "https://reference.wolfram.com/language/ref/DSolveValue.en.md"
  - 
    title: "NBodySimulation"
    link: "https://reference.wolfram.com/language/ref/NBodySimulation.en.md"
related_tutorials: 
  - 
    title: "Getting Started with Model Simulation and Analysis"
    link: "https://reference.wolfram.com/language/tutorial/GettingStartedWithModelSimulationAndAnalysis.en.md"
---
[EXPERIMENTAL]

# SystemModelCalibrate

SystemModelCalibrate[data, smodel, pars] calibrates the parameters pars in the system model smodel according to data.

SystemModelCalibrate[data, {smodel, cons}, pars] calibrates the parameters pars subject to the constraints cons.

SystemModelCalibrate[…, spec] calibrates following the specification spec.

SystemModelCalibrate[…, "prop"] gives the value of the property "prop".

## Details and Options

* ``SystemModelCalibrate`` is used to calibrate parameter values in a system model to match simulation results with real-world data.

[image]

* Given measured ``data`` $x\left(t_j\right)=\left\{x_1\left(t_j\right),\ldots ,x_n\left(t_j\right)\right\}$ from the real-world system, the goal is to calibrate parameters ``pars`` $\theta$ in the ``smodel`` to produce simulated data $\xi (\theta ,t)=\left\{\xi _1(\theta ,t),\ldots ,\xi _n(\theta ,t)\right\}$ that is as close as possible to the measured data.

* The calibrated parameters are $\hat{\theta }=\text{argmin}_{\theta }\sum _{i=1}^n w_i \ell \left(x_i,\xi _i(\theta )\right)$, where $w_i$ are non-negative weights and ``ℓ`` is a loss function with typical form $\ell \left(x_i,\xi _i(\theta )\right)=\int_{t_{\min }}^{t_{\max }} \left(x_i(t)-\xi _i(\theta ,t)\right){}^2 \, dt$, which is approximated by the sampled data as $\tilde{\ell }\left(x_i,\xi _i(\theta )\right)=\sum _{j=1}^{m_i} \left(x_i\left(t_j\right)-\xi _i\left(\theta ,t_j\right)\right){}^2$.

* Several quality measures of how well data and calibrated model agree can be computed as properties.

[image]

* The system model ``smodel`` can have the following forms:

|                             |                             |
| --------------------------- | --------------------------- |
| SystemModel[…]              | general system model        |
| StateSpaceModel[…]          | state-space model           |
| TransferFunctionModel[…]    | transfer function model     |
| AffineStateSpaceModel[…]    | affine state-space model    |
| NonlinearStateSpaceModel[…] | nonlinear state-space model |
| DiscreteInputOutputModel[…] | discrete input-output model |

* ``data`` is an association of the form ``<|x1 -> data1, …|>``, where ``xi`` is a variable in ``smodel`` and ``datai`` is its corresponding data.

* ``pars`` is a list of tunable parameters in ``smodel``. It can have the following forms:

|                |                                                                                                    |
| -------------- | -------------------------------------------------------------------------------------------------- |
| {θ1, …}        | calibration parameters starting from values in smodel                                              |
| {{θ1, θ10}, …} | calibration parameter θi starting from point $\theta _i=\theta _i^0$ |

* ``spec`` is an ``Association`` that allows the following keys:

|                       |                 |                                                                               |
| --------------------- | --------------- | ----------------------------------------------------------------------------- |
| "SimulationInterval"  | {tmin, tmax}    | simulate from time tmin to tmax                                               |
| "ParameterValues"     | {p1 -> val1, …}  | parameter pi has value vali                                                   |
| "InitialValues"       | {x1 -> val1, …}  | variable xi has initial value vali                                            |
| "Inputs"              | {in1 -> fun1, …} | input ini has value funi[t] at time t                                         |
| "CalibratedModelName" | name            | name for calibrated SystemModel                                               |
| "ExtendModel"         | False           | whether the calibrated SystemModel extends smodel                             |
| "Weights"             | {w1, …}         | positive multi-objective sum weights wi for each calibration variable in data |

* The ``"CalibratedModelName"`` ``name`` can have the following forms:

|           |                                               |
| --------- | --------------------------------------------- |
| Automatic | automatically generate a model name (default) |
| "name"    | name calibrated model "name"                  |
| None      | set calibrated values in place in smodel      |

* By default, ``SystemModelCalibrate[data, smodel, pars, spec]`` returns a model with parameters set to the calibrated values.

### Properties

* ``SystemModelCalibrate[…, "CalibratedSystemModel"]`` returns a ``CalibratedSystemModel`` object ``csmodel`` that can be used to extract additional properties using the form ``csmodel["prop"]``.

* ``SystemModelCalibrate[…, "prop"]`` can be used to directly get the value of ``csmodel["prop"]``.

* Typical properties that can be retrieved with ``SystemModelCalibrate[…, "prop"]`` include:

|                             |                                                                             |
| --------------------------- | --------------------------------------------------------------------------- |
| "CalibratedModel"           | new model with calibrated parameters                                        |
| "CalibratedParameters"      | parameter estimates                                                         |
| "ParameterConfidence"       | parameter confidence information                                            |
| "MeanPredictionBandsPlot"   | mean predictions confidence bands plot with calibration data                |
| "SinglePredictionBandsPlot" | plot of confidence bands based on single observations with calibration data |

* Properties related to data and the calibrated model include:

|                                    |                                                    |
| ---------------------------------- | -------------------------------------------------- |
| "CalibratedSimulationData"         | calibrated model simulation results                |
| "CalibrationData"                  | calibration data in data                           |
| "ValidationData"                   | validation set data                                |
| "CalibratedModelName"              | model name of new model with calibrated parameters |
| "CalibrationDataResponse"          | response values in the calibration data            |
| "ValidationDataResponse"           | response values in the validation data             |
| "CalibratedDataResponse"           | calibrated model values for the calibration data   |
| "CalibratedValidationDataResponse" | calibrated model values for the validation data    |

* Types of residuals include:

|                            |                                                                                |
| -------------------------- | ------------------------------------------------------------------------------ |
| "CalibrationDataResiduals" | difference between actual and predicted responses                              |
| "ValidationDataResiduals"  | difference between validation and predicted responses                          |
| "StandardizedResiduals"    | residuals for calibration data divided by the standard error for each residual |

* Properties of predicted values include:

|                              |                                                                                              |
| ---------------------------- | -------------------------------------------------------------------------------------------- |
| "CorrelationMatrix"          | asymptotic parameter correlation matrix                                                      |
| "MeanPredictionBands"        | confidence bands for mean predictions                                                        |
| "MeanPredictionConfidence"   | confidence information for the mean predictions of calibration data                          |
| "SinglePredictionBands"      | confidence bands based on single observations                                                |
| "SinglePredictionConfidence" | confidence information for the predicted response of single observations of calibration data |

* Properties that measure goodness of calibration include:

|     |     |
| --- | --- |
| "MSE" | mean squared error for each calibration variable, i.e. $\text{MSE}_i=m_i{}^{-1}\sum _{j=1}^{m_i} \left(x_i\left(t_j\right)-\xi _i\left(\hat{\theta },t_j\right)\right){}^2$ |
| "RMSE" | root mean squared error for each calibration variable, i.e. $\text{RMSE}_i=\text{MSE}_i{}^{1/2}$ |
| "RRMSE" | relative root mean squared error for each calibration variable, i.e. $\text{RRMSE} ... ^2\right)/\left(w_i\sum _{j=1}^{m_i} x_i\left(t_j\right){}^2\right)\right){}^{1/2}$ |

* Properties that store calibration details include:

|                                   |                                                                |
| --------------------------------- | -------------------------------------------------------------- |
| "CalibrationParameterConstraints" | calibration parameter constraints cons                         |
| "CalibrationVariables"            | calibration variables in data                                  |
| "InitialCalibrationParameters"    | calibration parameters pars and their calibration start values |
| "InputModel"                      | model smodel                                                   |
| "InputModelName"                  | model name of SystemModel smodel                               |
| "SimulationInterval"              | simulation interval used in calibration                        |

### Options

* The following options can be given:

|                            |                     |                                                 |
| -------------------------- | ------------------- | ----------------------------------------------- |
| ConfidenceLevel            | 95 / 100            | confidence level for parameters and predictions |
| FitRegularization          | None                | regularization for pars                         |
| Method                     | Automatic           | what simulation and calibration methods to use  |
| NormFunction               | Norm                | the norm to minimize                            |
| ProgressReporting          | \$ProgressReporting | control display of progress                     |
| ValidationSet              | None                | validation data                                 |
| VarianceEstimatorFunction  | Automatic           | function for estimating the error variance      |

* With ``ConfidenceLevel -> p``, probability-``p`` confidence intervals are computed for parameter and prediction intervals.

* ``FitRegularization`` and ``NormFunction`` can be used to change the calibration target into $\hat{\theta }=\text{argmin}_{\theta }\sum _{i=1}^n w_i \ell \left(x_i,\xi _i(\theta )\right)+g(\theta )$, where $g(\theta )$ is a regularization function, e.g. $g(\theta )=\lambda  \| \theta \| _2{}^2$ (Tikhonov) or $g(\theta )=\lambda  \| \theta \| _1$ (Lasso), and the loss function is given by $\ell (x,y)=h(x-y)$, where $h$ is the norm function.

* The following settings for ``ValidationSet`` can be given:

|              |                                                                     |
| ------------ | ------------------------------------------------------------------- |
| None         | use only the existing calibration data to measure quality (default) |
| data         | validation set in the same form as calibration data data            |
| Scaled[frac] | reserve a specified fraction of the calibration data for validation |

* With the setting ``VarianceEstimatorFunction -> f``, the common variance is estimated by ``f[res, w]``, where ``res`` is the list of residuals and ``w`` is the list of weights.

* Method settings take the form Method -> <\|"Subscript[sub, 1]"->Subscript[val, 1],\[Ellipsis]\|>.

* Method suboptions "Subscript[sub, i]" include:

|                     |           |                    |
| ------------------- | --------- | ------------------ |
| "CalibrationMethod" | Automatic | calibration method |
| "SimulationMethod"  | Automatic | simulation method  |

* ``"CalibrationMethod"`` settings are the same as the ``Method`` settings in ``FindMinimum``.

* ``"SimulationMethod"`` settings are the same as the ``Method`` settings in ``SystemModelSimulate``.

* Distributional assumptions are based on an unconstrained model calibrated by minimizing the default loss function.

---

## Examples (29)

### Basic Examples (2)

Use data of the angular velocity of a component to calibrate a model of a hybrid motor:

```wl
In[1]:= model = [image];

In[2]:= dataw = {...};
```

Calibrate the values of the resistance and the damping:

```wl
In[3]:= cmodel = SystemModelCalibrate[<|"Inertia2.w" -> dataw|>, model, {"Resistor1.R", "SpringDamper1.d"}]

Out[3]= [image]
```

Simulate with the calibrated parameters and compare with the data:

```wl
In[4]:= Show[SystemModelPlot[cmodel, {"Inertia2.w"}, 40], ListPlot[dataw, PlotStyle -> RGBColor[0.880722, 0.611041, 0.142051]], PlotRange -> All]

Out[4]= [image]
```

---

Use data of an output of a ``NonlinearStateSpaceModel`` to calibrate the model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{u + a*Cos[Subscript[x, 2]] - 
    Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate a parameter value:

```wl
In[3]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, nsys, {{a, 1}}, "CalibratedSystemModel"]

Out[3]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> NonlinearStateSpaceModel, 
  "InputModel" -> Hold[NonlinearStateSpaceModel[
     {{u + a*Cos[Subscript[x, 2]] - Cos[Subscript[x, 1]*S ... [{Association["Name" -> Subscript[\[FormalY], 1], "Data" -> CompressedData["«1571»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[4]:= csmodel["SinglePredictionBandsPlot"]//First

Out[4]= [image]
```

### Scope (14)

#### Data (3)

Provide data for as many variables as you want to calibrate:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{v, a + f - v - 
    9*x}, {x}}, {x, v}, {f}, 
 {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datax = {...};

In[3]:= datav = {...};
```

Calibrate a parameter value:

```wl
In[4]:= csmodel = SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, "CalibratedSystemModel"]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> NonlinearStateSpaceModel, 
  "InputModel" -> Hold[NonlinearStateSpaceModel[{{v, a + f - v - 9*x}, {x}}, {x, v}, {f}, 
     {Automatic ... ght" -> 1], 
     Association["Name" -> v, "Data" -> CompressedData["«377»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 5., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Simulate with the calibrated parameter and compare with the data:

```wl
In[5]:= csmodel["SinglePredictionBandsPlot"]//Dataset

Out[5]= Dataset[«1»]
```

---

Use data with units to calibrate a model of a rocket takeoff:

```wl
In[1]:= model = [image];

In[2]:= datam = QuantityArray[IconizedObject[«data»], {"Seconds", "Kilograms"}];
```

Calibrate the mass flow rate with data of the mass of the ship:

```wl
In[3]:= SystemModelCalibrate[<|"m" -> datam|>, {model, 0.39 < "k" < 0.46}, {"k"}, "CalibratedParameters"]

Out[3]= <|"k" -> 0.420977|>
```

---

Use the time-value pairs of a time series as data to calibrate a model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = TimeSeries[{...}];
```

Calibrate the values of two parameters:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}]

Out[3]=
NonlinearStateSpaceModel[
 {{0.7930120684603615 + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], -0.5957311572180536 + 
    Tanh[0.7930120684603615 + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None]
```

#### Models (4)

Use data generated with an input signal to calibrate a ``DiscreteInputOutputModel`` :

```wl
In[1]:=
diom = DiscreteInputOutputModel[Association["SampledSeries" -> TemporalData[TimeSeries, 
    {{{{a + u[0]}, {Rational[1, 2]*(u[0] + a*u[1])}, {Rational[1, 3]*(u[0] + a*u[1] + 2*a*u[2])}}}, 
     {{0, 2, 1}}, 1, {"Discrete", 1}, {"Discrete", 1}, {1}, {Miss ... ime", "LastValue", "OutputCount", "OutputVariables", "Path", 
  "PathComponent", "PathComponents", "PathFunction", "PathLength", "SamplingPeriod", "StateCount", 
  "TemporalData", "TimePath", "Times", "TimeSeries", "TimeValues", "Type", "Values"}];

In[2]:= datay = {...};

In[3]:= input = Sin[Range[-5, 5]];
```

Specify the input signal to calibrate a parameter value:

```wl
In[4]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, diom, {a}, <|"Inputs" -> {1 -> input}|>, "CalibratedSystemModel"]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> 1, 
  "InputModelNameOrHead" -> DiscreteInputOutputModel, 
  "InputModel" -> Hold[DiscreteInputOutputModel[Association["SampledSeries" -> 
       TemporalData[TimeSeries, {{ ... ta" -> 
   Hold[{Association["Name" -> y, "Data" -> CompressedData["«895»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[5]:= csmodel["SinglePredictionBandsPlot"]//First

Out[5]= [image]
```

---

Use data generated with an input signal to calibrate a ``TransferFunctionModel`` :

```wl
In[1]:=
tfm = TransferFunctionModel[{{{2*(1 - a*s)}}, 
  2*(1 + Rational[1, 2]*s + s^2)}, s];

In[2]:= datay = {...};

In[3]:= input = UnitStep;
```

Specify the input signal to calibrate a parameter value:

```wl
In[4]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, tfm, {a}, <|"Inputs" -> {1 -> input}|>, "CalibratedSystemModel"]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> TransferFunctionModel, 
  "InputModel" -> Hold[TransferFunctionModel[{{{2*(1 - a*s)}}, 2*(1 + Rational[1, 2]*s + s^2)}, 
     s]], "C ... [{Association["Name" -> Subscript[\[FormalY], 1], "Data" -> CompressedData["«1587»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[5]:= csmodel["SinglePredictionBandsPlot"]//First

Out[5]= [image]
```

---

Use data generated with an input signal to calibrate a ``StateSpaceModel`` :

```wl
In[1]:=
ssm = StateSpaceModel[{{{0, b}, {-a, -b}}, {{0}, {1}}, {{-1, 2}}, 
  {{0}}}, SamplingPeriod -> None, SystemsModelLabels -> None];

In[2]:= datay = {...};

In[3]:= input = Tanh;
```

Specify the input signal to calibrate parameter values:

```wl
In[4]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, ssm, {{a, 1}, {b, 1}}, <|"Inputs" -> {1 -> input}|>, "CalibratedSystemModel"]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> StateSpaceModel, "InputModel" -> 
   Hold[StateSpaceModel[{{{0, b}, {-a, -b}}, {{0}, {1}}, {{-1, 2}}, {{0}}}, SamplingPeriod -> None, ... d[{Association["Name" -> Subscript[\[FormalY], 1], "Data" -> CompressedData["«875»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[5]:= csmodel["SinglePredictionBandsPlot"]//First

Out[5]= [image]
```

---

Use data of the output of an ``AffineStateSpaceModel`` to calibrate the model:

```wl
In[1]:=
assm = AffineStateSpaceModel[{{a*Cos[Subscript[x, 2]] - 
    0.5*a*Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, {{1}, {0}}, 
  {-Subscript[x, 1]}, {{0}}}, {Subscript[x, 1], 
  Subscript[x, 2]}, {{u, 0}}, {Automatic}, Automatic, 
 SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate a parameter value:

```wl
In[3]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, assm, {{a, 1}}, "CalibratedSystemModel"]

Out[3]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> AffineStateSpaceModel, 
  "InputModel" -> Hold[AffineStateSpaceModel[
     {{a*Cos[Subscript[x, 2]] - 0.5*a*Cos[Subscript[x, 1]*Subsc ... [{Association["Name" -> Subscript[\[FormalY], 1], "Data" -> CompressedData["«1575»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[4]:= csmodel["SinglePredictionBandsPlot"]//First

Out[4]= [image]
```

#### Parameters and Constraints (2)

Indicate initial guess values for the calibration parameters:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate two parameter values:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {{a, 0.7}, {b, -0.5}}]

Out[3]=
NonlinearStateSpaceModel[
 {{0.7930120684773222 + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], -0.5957311572233015 + 
    Tanh[0.7930120684773222 + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None]
```

---

Introduce constraints for the calibration parameters:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate two parameter values:

```wl
In[3]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, {nsys, 0.75 < a < 0.8, -0.6 < b < -0.55}, {a, b}, "CalibratedSystemModel"]

Out[3]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> NonlinearStateSpaceModel, 
  "InputModel" -> Hold[NonlinearStateSpaceModel[{{a + Tanh[u - Subscript[x, 1]*Subscript[x, 2]], 
       b ... tion["Name" -> Subscript[\[FormalY], 1], 
      "Data" -> CompressedData["«359»"], 
      "Unit" -> "1", "AbsoluteValue" -> Missing[], "DataType" -> "ListOfPairs", "DataStart" -> 0., 
      "DataStop" -> 5., "Weight" -> 1]}], "ValidationData" -> Hold[{}]]]
```

Confidence intervals are computed assuming an unconstrained model:

```wl
In[4]:= csmodel["ParameterConfidence"]
```

Out[4]=
Estimate	Standard Error	Confidence Interval	t-Statistic	P-Value
a	0.79301	0.028842	{0.732643,0.853378}	27.495	9.1561\*10^-17
b	-0.59573	0.0083293	{-0.613164,-0.578297}	-71.522	1.4325\*10^-24

#### Specification (4)

Specify a model name for the calibrated model:

```wl
In[1]:= model = [image];

In[2]:= datay = {...};
```

Calibrate the value of a parameter, specifying the calibrated model name:

```wl
In[3]:= SystemModelCalibrate[<|"y" -> datay|>, {model, 3 < "a" < 5}, {"a"}, <|"CalibratedModelName" -> "MyCalibratedModel"|>]

Out[3]= [image]
```

Create a calibrated model that extends the input model:

```wl
In[4]:= cmodel = SystemModelCalibrate[<|"y" -> datay|>, {model, 3 < "a" < 5}, {"a"}, <|"CalibratedModelName" -> "ExtendsInputModel", "ExtendModel" -> True|>]

Out[4]= [image]

In[5]:= cmodel["ExtendsModels"]

Out[5]= {[image]}
```

---

Use data generated with an input signal to calibrate a model:

```wl
In[1]:=
ssm = StateSpaceModel[{{{0, b}, {-a, -b}}, {{0}, {1}}, {{-1, 2}}, 
  {{0}}}, SamplingPeriod -> None, SystemsModelLabels -> None];

In[2]:= datay = {...};

In[3]:= input = Tanh;
```

Specify the input signal to calibrate parameter values:

```wl
In[4]:= SystemModelCalibrate[<|1 -> datay|>, ssm, {{a, 1}, {b, 1}}, <|"Inputs" -> {1 -> input}|>]

Out[4]=
StateSpaceModel[{{{0, 1.543240797446037}, {-1.9970885513806294, -1.543240797446037}}, {{0}, {1}}, 
  {{-1, 2}}, {{0}}}, SamplingPeriod -> None, SystemsModelLabels -> None]
```

Specify a fixed value for a parameter to calibrate another:

```wl
In[5]:= SystemModelCalibrate[<|1 -> datay|>, ssm, {{a, 1}}, <|"Inputs" -> {1 -> input}, "ParameterValues" -> {b -> 1.54}|>]

Out[5]=
StateSpaceModel[{{{0, b}, {-1.9977678011406166, -b}}, {{0}, {1}}, 
  {{-1, 2}}, {{0}}}, SamplingPeriod -> None, SystemsModelLabels -> None]
```

---

Specify initial values and a simulation interval to calibrate a model:

```wl
In[1]:=
assm = AffineStateSpaceModel[{{a*Cos[Subscript[x, 2]] - 
    0.5*a*Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, {{1}, {0}}, 
  {-Subscript[x, 1]}, {{0}}}, {Subscript[x, 1], 
  Subscript[x, 2]}, {{u, 0}}, {Automatic}, Automatic, 
 SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate a parameter value:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, assm, {{a, 1}}, <|"InitialValues" -> {Subscript[x, 1] -> 0.01}, "SimulationInterval" -> {0, 5}|>]

Out[3]=
AffineStateSpaceModel[{{0.884163679883688*Cos[Subscript[x, 2]] - 
    0.442081839941844*Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, {{1}, {0}}, 
  {-Subscript[x, 1]}, {{0}}}, {Subscript[x, 1], 
  Subscript[x, 2]}, {{u, 0}}, {Automatic}, Automatic, 
 SamplingPeriod -> None]
```

---

Provide weights for the calibration of several variables:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{v, a + f - v - 
    9*x}, {x}}, {x, v}, {f}, 
 {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datax = {...};

In[3]:= datav = {...};

In[4]:= weights = {1, 2};
```

Calibrate a parameter value:

```wl
In[5]:= csmodel = SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, <|"Weights" -> weights|>, "CalibratedSystemModel"]

Out[5]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> NonlinearStateSpaceModel, 
  "InputModel" -> Hold[NonlinearStateSpaceModel[{{v, a + f - v - 9*x}, {x}}, {x, v}, {f}, 
     {Automatic ... ght" -> 1], 
     Association["Name" -> v, "Data" -> CompressedData["«377»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 5., "Weight" -> 2]}], 
  "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[6]:= csmodel["SinglePredictionBandsPlot"]//Dataset

Out[6]= Dataset[«1»]
```

#### Properties (1)

Find the list of available properties:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{u + a*Cos[Subscript[x, 2]] - 
    Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};

In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {{a, 1}}, "Properties"]//Shallow

Out[3]//Shallow= {"ARMSE", "ARRMSE", "CalibratedDataResponse", "CalibratedModel", "CalibratedModelName", "CalibratedParameters", "CalibratedSimulationData", "CalibratedValidationDataResponse", "CalibrationData", "CalibrationDataResiduals", «23»}
```

These can be extracted more conveniently from the ``CalibratedSystemModel`` :

```wl
In[4]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, nsys, {{a, 1}}, "CalibratedSystemModel"]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> NonlinearStateSpaceModel, 
  "InputModel" -> Hold[NonlinearStateSpaceModel[
     {{u + a*Cos[Subscript[x, 2]] - Cos[Subscript[x, 1]*S ... [{Association["Name" -> Subscript[\[FormalY], 1], "Data" -> CompressedData["«1571»"], "Unit" -> "1", "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 10., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]

In[5]:= csmodel["Properties"]

Out[5]= {"ARMSE", "ARRMSE", "CalibratedDataResponse", "CalibratedModel", "CalibratedModelName", "CalibratedParameters", "CalibratedSimulationData", "CalibratedValidationDataResponse", "CalibrationData", "CalibrationDataResiduals", "CalibrationDataResponse" ... MSE", "ParameterConfidence", "RMSE", "RRMSE", "SimulationInterval", "SinglePredictionBands", "SinglePredictionBandsPlot", "SinglePredictionConfidence", "StandardizedResiduals", "ValidationData", "ValidationDataResiduals", "ValidationDataResponse"}
```

Extract the single prediction bands plot:

```wl
In[6]:= csmodel["SinglePredictionBandsPlot"]//First

Out[6]= [image]
```

Extract the single prediction bands plot with a custom confidence level:

```wl
In[7]:= csmodel["SinglePredictionBandsPlot", ConfidenceLevel -> 0.5]//First

Out[7]= [image]
```

Extract the single prediction bands plot with a custom variance estimator function:

```wl
In[8]:= csmodel["SinglePredictionBandsPlot", VarianceEstimatorFunction -> (Mean[Abs[#]]&)]//First

Out[8]= [image]
```

Extract the calibrated model and the calibrated parameters:

```wl
In[9]:= csmodel[{"CalibratedModel", "CalibratedParameters"}]

Out[9]=
{NonlinearStateSpaceModel[{{u + 2.000298644240828*Cos[Subscript[x, 2]] - 
    Cos[Subscript[x, 1]*Subscript[x, 2]], 
   -Cos[1 + Subscript[x, 2]] + Subscript[x, 1]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None], <|a -> 2.0003|>}
```

Extract the single prediction bands:

```wl
In[10]:= csmodel["SinglePredictionBands"]//Short

Out[10]//Short= <|Subscript[\[FormalY], 1] -> {-10 Sqrt[-1 + «1»] Sqrt[0.00304242  + 0.0000106047 «1»^2] + «1», «1»}|>
```

Extract the single prediction bands evaluated at time ``t`` :

```wl
In[11]:= csmodel["SinglePredictionBands", t]//Short

Out[11]//Short= <|Subscript[\[FormalY], 1] -> {-10 Sqrt[-1 + «1»] Sqrt[0.00304242  + 0.0000106047 «1»^2] + «1», «1»}|>
```

Extract the root mean squared error for each calibration variable:

```wl
In[12]:= csmodel["MSE"]
```

Out[12]= Subscript[\[FormalY], 1]	0.0030123

Extract the root mean squared error for each calibration variable providing a validation set:

```wl
In[13]:= csmodel["MSE", ValidationSet -> <|1 -> {{2.6, 1.8}, {2.7, 1.56}, {2.8, 1.4}, {2.9, 1.2}, {3., 1.2}, {3.1, 1.0}, {3.2, 1.0}, {3.3, 0.8}}|>]
```

Out[13]=
Subscript[\[FormalY], 1]	Calibration Set	0.0030123
\[SpanFromAbove]	Validation Set	0.0028854

Extract parameter confidence information, including estimates, standard errors, confidence intervals, $t$-statistics for parameter estimates, and $p$‐values for parameter $z$‐statistics:

```wl
In[14]:= csmodel["ParameterConfidence"]
```

Out[14]=
Estimate	Standard Error	Confidence Interval	t-Statistic	P-Value
a	2.0003	0.0032565	{1.99384,2.00676}	614.25	1.1498\*10^-180

### Options (8)

#### ConfidenceLevel (1)

Use data of the states of a model to calibrate a parameter:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{v, a + f - v - 
    9*x}, {x}}, {x, v}, {f}, 
 {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datax = {...};

In[3]:= datav = {...};
```

Use the default confidence level:

```wl
In[4]:= SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, "SinglePredictionBandsPlot"]

Out[4]= <|x -> [image], v -> [image]|>
```

Specify a custom confidence level of 0.5:

```wl
In[5]:= SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, "SinglePredictionBandsPlot", ConfidenceLevel -> 0.5]

Out[5]= <|x -> [image], v -> [image]|>
```

#### FitRegularization (1)

Use data of an output to calibrate a model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Use a loss function with no regularization to calibrate parameters:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters"]

Out[3]= <|a -> 0.793012, b -> -0.595731|>
```

Use a Lasso regularization to calibrate parameters:

```wl
In[4]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters", FitRegularization -> {"LASSO", 2}]

Out[4]= <|a -> 0.698076, b -> -0.565026|>
```

Use a Tikhonov regularization to calibrate parameters:

```wl
In[5]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters", FitRegularization -> {"Tikhonov", 2}]

Out[5]= <|a -> 0.659168, b -> -0.55001|>
```

#### Method (2)

Use data of the mass of a ship to calibrate a model of a rocket takeoff:

```wl
In[1]:= model = [image];

In[2]:= datam = IconizedObject[«data»];
```

Use the default simulation method to calibrate the value of the mass flow rate:

```wl
In[3]:= SystemModelCalibrate[<|"m" -> datam|>, {model, 0.39 < "k" < 0.46}, {"k"}, "SinglePredictionBandsPlot"]//First

Out[3]= [image]
```

Calibrate, specifying a number of interpolation points for simulation:

```wl
In[4]:= SystemModelCalibrate[<|"m" -> datam|>, {model, 0.39 < "k" < 0.46}, {"k"}, "SinglePredictionBandsPlot", Method -> <|"SimulationMethod" -> {"InterpolationPoints" -> 30}|>]//First

Out[4]= [image]
```

---

Use data of an output to calibrate a model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Use the default fitting method to calibrate parameters:

```wl
In[3]:= csmodel = SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedSystemModel"];

In[4]:= csmodel["CalibratedParameters"]

Out[4]= <|a -> 0.793012, b -> -0.595731|>

In[5]:= csmodel["SinglePredictionBandsPlot"]//First

Out[5]= [image]
```

Use the conjugate gradient method to calibrate parameters:

```wl
In[6]:= csmodelg = SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedSystemModel", Method -> <|"CalibrationMethod" -> "ConjugateGradient"|>];

In[7]:= csmodelg["CalibratedParameters"]

Out[7]= <|a -> 1.43195, b -> 0.809349|>

In[8]:= csmodelg["SinglePredictionBandsPlot"]//First

Out[8]= [image]
```

#### NormFunction (1)

Use data of an output to calibrate a model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Use the default norm in the loss function to calibrate parameters:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters"]

Out[3]= <|a -> 0.793012, b -> -0.595731|>
```

Use the $\infty$-norm in the loss function to calibrate parameters:

```wl
In[4]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters", NormFunction -> (Norm[#, Infinity]&)]

Out[4]= <|a -> 0.772918, b -> -0.606383|>
```

Use the 1-norm in the loss function to calibrate parameters

```wl
In[5]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "CalibratedParameters", NormFunction -> (Norm[#, 1]&)]

Out[5]= <|a -> 0.782211, b -> -0.595279|>
```

#### ProgressReporting (1)

Use data of the mass of a ship to calibrate a model of a rocket takeoff:

```wl
In[1]:= model = [image];

In[2]:= datam = IconizedObject[«data»];
```

Calibrate the value of the mass flow rate with the default progress reporting:

```wl
In[3]:= SystemModelCalibrate[<|"m" -> datam|>, {model, 0.39 < "k" < 0.46}, {"k"}, "CalibratedParameters"]

Out[3]= <|"k" -> 0.420977|>
```

Calibrate without progress reporting:

```wl
In[4]:= SystemModelCalibrate[<|"m" -> datam|>, {model, 0.39 < "k" < 0.46}, {"k"}, "CalibratedParameters", ProgressReporting -> False]

Out[4]= <|"k" -> 0.420977|>
```

#### ValidationSet (1)

Use data of an output to calibrate a model:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[
 {{a + Tanh[u - Subscript[x, 1]*
       Subscript[x, 2]], b + 
    Tanh[a + u*Subscript[x, 2]]}, 
  {Subscript[x, 1]}}, {Subscript[x, 1], Subscript[x, 2]}, 
 {u}, {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datay = {...};
```

Calibrate parameters using no validation data:

```wl
In[3]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "RMSE"]
```

Out[3]= Subscript[\[FormalY], 1]	0.10529

Calibrate parameters by reserving a fraction of the calibration data for validation:

```wl
In[4]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "RMSE", ValidationSet -> Scaled[0.1]]
```

Out[4]=
Subscript[\[FormalY], 1]	Calibration Set	0.10983
\[SpanFromAbove]	Validation Set	0.045319

Use a particular random seed in the selection of validation data to ensure predictable results:

```wl
In[5]:= BlockRandom[SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "RMSE", ValidationSet -> Scaled[0.1]], RandomSeeding -> 1234]
```

Out[5]=
Subscript[\[FormalY], 1]	Calibration Set	0.099281
\[SpanFromAbove]	Validation Set	0.15285

Use a custom validation set to calibrate parameters:

```wl
In[6]:= SystemModelCalibrate[<|1 -> datay|>, nsys, {a, b}, "RMSE", ValidationSet -> <|1 -> {{0.75, 0.9}, {1., 0.7}, {1.25, 1.1}, {1.5, 1.2}, {1.75, 1.15}}|>]
```

Out[6]=
Subscript[\[FormalY], 1]	Calibration Set	0.10529
\[SpanFromAbove]	Validation Set	0.17339

#### VarianceEstimatorFunction (1)

Use data of the states of a model to calibrate a parameter:

```wl
In[1]:=
nsys = NonlinearStateSpaceModel[{{v, a + f - v - 
    9*x}, {x}}, {x, v}, {f}, 
 {Automatic}, Automatic, SamplingPeriod -> None];

In[2]:= datax = {...};

In[3]:= datav = {...};
```

Use the default estimate of error variance:

```wl
In[4]:= SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, "SinglePredictionBandsPlot"]

Out[4]= <|x -> [image], v -> [image]|>
```

Estimate the variance by the mean absolute error:

```wl
In[5]:= SystemModelCalibrate[<|x -> datax, v -> datav|>, nsys, {a}, "SinglePredictionBandsPlot", VarianceEstimatorFunction -> (Mean[Abs[#]]&)]

Out[5]= <|x -> [image], v -> [image]|>
```

### Applications (5)

#### Industrial Manufacturing (1)

Use temperature data to estimate the heat transfer coefficient in a model of a continuous stirred-tank reactor:

```wl
In[1]:= model = [image];
```

Use the measured temperature of the tank and the cooling medium:

```wl
In[2]:=
dataTr = QuantityArray[IconizedObject[«dataTr»], {"Hours", "Kelvins"}];
dataTj = QuantityArray[IconizedObject[«dataTj»], {"Hours", "Kelvins"}];
```

Set the cooling medium flow rate used in the measurement as input:

```wl
In[3]:= mediumFlowRate = <|"Inputs" -> {"FJ" -> Function[0.02]}|>;
```

Fit the heat transfer coefficient:

```wl
In[4]:= csmodel = Quiet[SystemModelCalibrate[<|"TR" -> dataTr, "TJ" -> dataTj|>, model, {"U"}, mediumFlowRate, "CalibratedSystemModel", Method -> <|"CalibrationMethod" -> "PrincipalAxis"|>], {FindMinimum::fmmp}]

Out[4]=
CalibratedSystemModel[Association["WLModel" -> False, "WLSamplingPeriod" -> Missing[], 
  "InputModelNameOrHead" -> "DocumentationExamples.Modeling.CSTR", 
  "InputModel" -> Hold["DocumentationExamples.Modeling.CSTR"], 
  "CalibrationParameterConst ...  311.0107131515352}, {28680, 310.713842385954}, {28800, 311.1440598817996}}, 
      "Unit" -> "K", "AbsoluteValue" -> True, "DataType" -> "ListOfPairs", "DataStart" -> 0, 
      "DataStop" -> 28800, "Weight" -> 1]}], "ValidationData" -> Hold[{}]]]
```

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[5]:= csmodel["SinglePredictionBandsPlot"]//Dataset

Out[5]=
Dataset[Association[
  "TR" -> Graphics[{Annotation[{GraphicsComplex[CompressedData["«14601»"], {{{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, 
          {EdgeForm[], Directive[RGBColor[0.95, 0.627, 0.1425], Opacity[0.2]], 
           Gr ... [#1] & )[#1[[1]]], (Identity[#1] & )[#1[[2]]]} & )}, "AxesInFront" -> True}, 
     PlotRange -> {All, All}, PlotRangeClipping -> True, PlotRangePadding -> 
      {{Automatic, Automatic}, {Automatic, Automatic}}, Ticks -> {Automatic, Automatic}}]]]
```

Plot the residuals against time for the tank temperature:

```wl
In[6]:= ListPlot[Transpose[{dataTr[[All, 1]], csmodel["CalibrationDataResiduals"]["TR"]}], Sequence[Frame -> True, Filling -> Axis, FrameLabel -> {"h", "residual TR"}, PlotLabel -> "Residual vs Time"]]

Out[6]= [image]
```

#### Model Simplification (1)

Recreate the behavior of a speaker by calibrating a simpler circuit using simulation results as input data:

```wl
In[1]:= speaker = [image];

In[2]:= rl = [image];
```

Compare the behavior of both models before calibration:

```wl
In[3]:= sims = SystemModelSimulate[speaker];

In[4]:= simrl = SystemModelSimulate[rl];

In[5]:= SystemModelPlot[{sims, simrl}, {"vs.v"}]

Out[5]= [image]
```

Retrieve simulation results as data and use them for calibration:

```wl
In[6]:= datav = sims["RawData", "vs.v"];

In[7]:= csmodel = SystemModelCalibrate[<|"vs.v" -> datav|>, {rl, 0.001 < l < 0.5}, {l}, "CalibratedSystemModel"]

Out[7]=
CalibratedSystemModel[Association["WLModel" -> False, "WLSamplingPeriod" -> Missing[], 
  "InputModelNameOrHead" -> "DocumentationExamples.Modeling.ElectricCircuit.SeriesRL", 
  "InputModel" -> Hold["DocumentationExamples.Modeling.ElectricCircuit.S ... 
   Hold[{Association["Name" -> "vs.v", "Data" -> CompressedData["«33117»"], "Unit" -> "V", 
      "AbsoluteValue" -> False, "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 0.1, 
      "Weight" -> 1]}], "ValidationData" -> Hold[{}]]]
```

Compare the calibrated model with the speaker:

```wl
In[8]:= SystemModelPlot[{sims, csmodel["CalibratedSimulationData"]}, {"vs.v"}]

Out[8]= [image]
```

#### Conveyor Belt Friction (1)

Calibrate the viscous contribution to friction in a model of a body held by a spring on top of an accelerating conveyor belt:

```wl
In[1]:= beltv[t_] := vb + ab t;
```

The total kinetic friction can be modeled as a combination of viscous, Coulomb and Stribeck components:

```wl
In[2]:= viscous[v_] := -d (v - beltv[t]);

In[3]:= coulomb[v_] := -c Sign[v - beltv[t]];

In[4]:= stribeck[v_] := -s Sign[v] Exp[-σ Abs[v]];

In[5]:= friction[v_] := viscous[v] + coulomb[v] + stribeck[v];
```

The equations of motion must include the event-generating effect of the static friction, which holds the body static with respect to the belt until an upper bound is breached by external forces:

```wl
In[6]:= spring[x_] := -k (x - l);

In[7]:=
eqs = {m v'[t] == If[stuck[t] == 1, m beltv'[t], spring[x[t]] + friction[v[t]]], 
	x'[t] == v[t], WhenEvent[v[t] == beltv[t], stuck[t] -> Boole[spring[x[t]]^2 < μ^2]], WhenEvent[spring[x[t]]^2 > μ^2, stuck[t] -> 0]};
```

Set initial values for the position and velocity of the body and the discrete variable tracking the impact of static friction:

```wl
In[8]:= initeqs = {x[0] == 1, v[0] == 0, stuck[0] == 0};
```

Set parameter values and create the system model:

```wl
In[9]:= parVals = {m -> 1, l -> 1, d -> 5, c -> 5, s -> 1, μ -> 100, k -> 1000, σ -> 2, vb -> 1 / 10, ab -> 1 / 100};

In[10]:= model = CreateSystemModel["ConveyorBeltFriction", Join[eqs, initeqs], t, <|"DiscreteVariables" -> {stuck}, "ParameterValues" -> parVals|>]
```

CreateSystemModel::eeps: An epsilon was introduced in if condition to prevent event chatter around stuck[t]==1.

CreateSystemModel::eeps: An epsilon was introduced in when equation to prevent event chatter around v[t]==ab t+vb.

```wl
Out[10]= [image]
```

Calibrate the contribution of the viscous term with data for the position of the body:

```wl
In[11]:= datax = {...};

In[12]:= csmodel = SystemModelCalibrate[<|x -> datax|>, {model, 1 < d < 20}, {d}, "CalibratedSystemModel"]

Out[12]=
CalibratedSystemModel[Association["WLModel" -> False, "WLSamplingPeriod" -> Missing[], 
  "InputModelNameOrHead" -> "ConveyorBeltFriction", "InputModel" -> Hold["ConveyorBeltFriction"], 
  "CalibrationParameterConstraints" -> Hold[{1 < "d" < 20}],  ...    Hold[{Association["Name" -> "x", "Data" -> CompressedData["«2381»"], "Unit" -> Missing[], "AbsoluteValue" -> Missing[], 
      "DataType" -> "ListOfPairs", "DataStart" -> 0., "DataStop" -> 3., "Weight" -> 1]}], 
  "ValidationData" -> Hold[{}]]]
```

Find the 95% confidence interval for the viscous friction factor:

```wl
In[13]:= csmodel["ParameterConfidence"]
```

Out[13]=
Estimate	Standard Error	Confidence Interval	t-Statistic	P-Value
d	10.112	0.049868	{10.0136,10.2106}	202.78	7.0655\*10^-185

Compute the single prediction bands and plot them together with the data and the calibrated simulation response:

```wl
In[14]:= csmodel["SinglePredictionBandsPlot"]//First

Out[14]= [image]
```

Compute the extremes of the position and velocity for the calibrated simulation data:

```wl
In[15]:= SystemModelMeasurements[csmodel["CalibratedSimulationData"], {"MinValue", "MaxValue"}]
```

Out[15]=
Output	MinValue	MaxValue
v	-2.3632	0.13
x	0.94973	1.1001

#### Reverse Engineering of Controller (1)

Deduce the controller parameters in a controlled system for which you have step response data:

```wl
In[1]:=
plant = TransferFunctionModel[{{{6}}, (1 + 2*s)*(1 + 4*s)*
   (1. + 6*s)}, s];

In[2]:= csys = PIDTune[plant, "PID", "ReferenceOutput"];

In[3]:= sim = SystemModelSimulate[csys, 50, <|"Inputs" -> {1 -> UnitStep}|>];

In[4]:= data = sim["RawData", Subscript[\[FormalY], 1]];
```

Connect the plant model to a controller with symbolic parameters:

```wl
In[5]:=
pid = TransferFunctionModel[{{{s^2*Subscript[k, d] + 
     Subscript[k, i] + s*Subscript[k, 
       p]}}, s}, s];

In[6]:= csysWithPars = SystemsModelFeedbackConnect[SystemsModelSeriesConnect[pid, plant]];
```

Calibrate the parameters in the model with the step response data of the controlled system:

```wl
In[7]:= csmodel = SystemModelCalibrate[<|1 -> data|>, {csysWithPars, 0.01 < Subscript[k, p] < 10, 0.01 < Subscript[k, i] < 10, 0.01 < Subscript[k, d] < 10}, {Subscript[k, p], Subscript[k, i], Subscript[k, d]}, <|"Inputs" -> {1 -> UnitStep}|>, "CalibratedSystemModel"]

Out[7]=
CalibratedSystemModel[Association["WLModel" -> True, "WLSamplingPeriod" -> Automatic, 
  "InputModelNameOrHead" -> TransferFunctionModel, 
  "InputModel" -> Hold[TransferFunctionModel[
     {{{6.*s^2*Subscript[k, d] + 6.*Subscript[k, i] + 6.*s*Subs ... n["Name" -> Subscript[\[FormalY], 1], 
      "Data" -> CompressedData["«33887»"], 
      "Unit" -> "1", "AbsoluteValue" -> Missing[], "DataType" -> "ListOfPairs", "DataStart" -> 0., 
      "DataStop" -> 50., "Weight" -> 1]}], "ValidationData" -> Hold[{}]]]
```

Compare the simulation results of the calibrated model with the reverse-engineered model:

```wl
In[8]:= SystemModelPlot[{sim, csmodel["CalibratedSimulationData"]}, {Subscript[\[FormalY], 1]}, PlotStyle -> {Automatic, Directive[RGBColor[0.922526, 0.385626, 0.209179], Dashed]}, PlotRange -> All]

Out[8]= [image]
```

#### Reduced Three-Body Problem (1)

Estimate the mass of a planet that orbits a star from the trajectory of one of its moons in a reduced three-body planetary system:

```wl
In[1]:= starPlanetSystemEqs = {μ12 r[t]^2θ'[t] == Sqrt[a (1 - e^2) \[ScriptCapitalG] m1 m2 μ12], r[t] == (a(1 - e^2)/1 + e Cos[θ[t] - θr]), {x1[t], y1[t]} == -(m2/m1 + m2){xr[t], yr[t]}, {x2[t], y2[t]} == (m1/m1 + m2){xr[t], yr[t]}, {xr[t], yr[t]} == r[t]{Cos[θ[t]], Sin[θ[t]]}};
```

The dynamics of the moon are dictated by Newtonian gravity:

```wl
In[2]:= moonEqs = {m3 vx3'[t] == -\[ScriptCapitalG] m1 m3(x3[t] - x1[t]/((x3[t] - x1[t])^2 + (y3[t] - y1[t])^2)^3 / 2) - \[ScriptCapitalG] m2 m3(x3[t] - x2[t]/((x3[t] - x2[t])^2 + (y3[t] - y2[t])^2)^3 / 2), m3 vy3'[t] == -\[ScriptCapitalG] m1 m3(y3[t] - y1[t]/((x3[t] - x1[t])^2 + (y3[t] - y1[t])^2)^3 / 2) - \[ScriptCapitalG] m2 m3(y3[t] - y2[t]/((x3[t] - x2[t])^2 + (y3[t] - y2[t])^2)^3 / 2), {vx3[t], vy3[t]} == {x3'[t], y3'[t]}};
```

Set parameter values for the system and initial values for the trajectory of the moon:

```wl
In[3]:= parVals = {\[ScriptCapitalG] -> 1, m1 -> 1, m2 -> 0.0059, m3 -> 0.00001, a -> 1, e -> 0.0549, θr -> 0, μ12 -> (m1 m2/m1 + m2)};

In[4]:= initVals = {x3 -> 0.9, vy3 -> 0.6};
```

Create a model from the equations, parameters and initial values:

```wl
In[5]:= model = CreateSystemModel["ReducedTBP", Join[starPlanetSystemEqs, moonEqs], t, <|"ParameterValues" -> parVals, "InitialValues" -> initVals|>]

Out[5]= [image]
```

Simulate the model before calibration and plot the trajectories of the three bodies:

```wl
In[6]:= sim = SystemModelSimulate[model, 4];

In[7]:= ParametricPlot[Evaluate[{sim[{x1, y1}, t], sim[{x2, y2}, t], sim[{x3, y3}, t]}], {t, 0, 4}, ...]

Out[7]= [image]
```

Calibrate a model with data for the trajectory of the moon:

```wl
In[8]:= datax3 = {...};

In[9]:= datay3 = {...};

In[10]:= csmodel = SystemModelCalibrate[<|x3 -> datax3, y3 -> datay3|>, {model, 0.001 < m2 < 0.007}, m2, "CalibratedSystemModel", Method -> <|"CalibrationMethod" -> "NMinimize"|>]

Out[10]=
CalibratedSystemModel[Association["WLModel" -> False, "WLSamplingPeriod" -> Missing[], 
  "InputModelNameOrHead" -> "ReducedTBP", "InputModel" -> Hold["ReducedTBP"], 
  "CalibrationParameterConstraints" -> Hold[{0.001 < "m2" < 0.007}], 
  "InitialC ...    Association["Name" -> "y3", "Data" -> CompressedData["«30595»"], "Unit" -> Missing[], 
      "AbsoluteValue" -> Missing[], "DataType" -> "ListOfPairs", "DataStart" -> 0., 
      "DataStop" -> 4., "Weight" -> 1]}], "ValidationData" -> Hold[{}]]]
```

Retrieve the simulation data and plot the trajectories for the calibrated model:

```wl
In[11]:= simcal = csmodel["CalibratedSimulationData"];

In[12]:= cPlot = ParametricPlot[Evaluate[{simcal[{x1, y1}, t], simcal[{x2, y2}, t], simcal[{x3, y3}, t]}], {t, 0, 4}, ...]

Out[12]= [image]
```

Compare the data with the calibrated trajectory:

```wl
In[13]:= Show[cPlot, ListPlot[Transpose[{datax3[[All, 2]], datay3[[All, 2]]}], PlotStyle -> RGBColor[0.922526, 0.385626, 0.209179], PlotLegends -> {"data"}]]

Out[13]= [image]
```

## See Also

* [`SystemModelSimulationData`](https://reference.wolfram.com/language/ref/SystemModelSimulationData.en.md)
* [`SystemModelExamples`](https://reference.wolfram.com/language/ref/SystemModelExamples.en.md)
* [`SystemModel`](https://reference.wolfram.com/language/ref/SystemModel.en.md)
* [`SystemModelSimulateSensitivity`](https://reference.wolfram.com/language/ref/SystemModelSimulateSensitivity.en.md)
* [`SystemModelPlot`](https://reference.wolfram.com/language/ref/SystemModelPlot.en.md)
* [`SystemModelParametricSimulate`](https://reference.wolfram.com/language/ref/SystemModelParametricSimulate.en.md)
* [`NDSolveValue`](https://reference.wolfram.com/language/ref/NDSolveValue.en.md)
* [`DSolveValue`](https://reference.wolfram.com/language/ref/DSolveValue.en.md)
* [`NBodySimulation`](https://reference.wolfram.com/language/ref/NBodySimulation.en.md)

## Tech Notes

* [Getting Started with Model Simulation and Analysis](https://reference.wolfram.com/language/tutorial/GettingStartedWithModelSimulationAndAnalysis.en.md)

## Related Guides

* [System Model Creation](https://reference.wolfram.com/language/guide/SystemModelCreation.en.md)
* [System Modeling Overview](https://reference.wolfram.com/language/guide/SystemModelingOverview.en.md)

## Related Links

* [Wolfram System Modeler Documentation](http://reference.wolfram.com/system-modeler/)

## History

* [Introduced in 2023 (13.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn133.en.md)