({{, (RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity])[model,{(Subscript[p, 1]),(Subscript[p, 2]),…}] 
simulates model and sensitivities to parameters (Subscript[p, i]) following experiment settings.}, {, (RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity])[model,(Subscript[t, max]),{(Subscript[p, 1]),(Subscript[p, 2]),…}] 
simulates from 0 to (Subscript[t, max]).}, {, (RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity])[model,{(Subscript[t, min]),(Subscript[t, max])},{(Subscript[p, 1]),(Subscript[p, 2]),…}] 
simulates from (Subscript[t, min]) to (Subscript[t, max]).}, {, (RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity])[model,vars,{(Subscript[t, min]),(Subscript[t, max])},{(Subscript[p, 1]),(Subscript[p, 2]),…}]
stores only simulation data for the variables vars.}})

OpenersNotesSection(Spacer1)Details and Options

The model can be a (RefLink[SystemModel, paclet:ref/SystemModel]) object, a full model name string or a shortened model name accepted by (RefLink[SystemModel, paclet:ref/SystemModel]).

(RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity]) returns a (RefLink[SystemModelSimulationData, paclet:ref/SystemModelSimulationData]) object.

(RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity]) generates solutions (Subscript[v, i])(t,(Subscript[p, 1]),(Subscript[p, 2]),…) for all variables (Subscript[v, i]), as well as derivatives ((∂(Subscript[s, i])(t,(Subscript[p, 1]),(Subscript[p, 2]),…))/(∂(Subscript[p, 1]))), ((∂(Subscript[s, i])(t,(Subscript[p, 1]),(Subscript[p, 2]),…))/(∂(Subscript[p, 2]))), … for all states (Subscript[s, i]), for (Subscript[t, min])≤t≤(Subscript[t, max]).

Sensitivities can be listed in a (RefLink[SystemModelSimulationData, paclet:ref/SystemModelSimulationData]) object sd with sd["SensitivityNames"].

The stored simulation variables vars can have the following values:

(RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity])[…,spec] uses (RefLink[Association, paclet:ref/Association]) spec for initial values, parameters and inputs:

Setting "ParameterValues" or "InitialValues" to {(Subscript[p, i])->{(Subscript[c, 1]),(Subscript[c, 2]),…},…} runs simulations in parallel, with (Subscript[p, i]) taking values (Subscript[c, j]).

"InitialValues" corresponds to the start property in the Modelica model.

The following options can be given:

The option setting (RefLink[Automatic, paclet:ref/Automatic]) normally means that the setting is taken from model or its experiment setting.

The CVODES solver used can be controlled with (RefLink[Method, paclet:ref/Method])->{"(Subscript[opt, 1])"->(Subscript[val, 1])}.

Possible suboptions for the CVODES method include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (29)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Study sensitivity of a parameter over the time interval in model experiment settings:

sim=SystemModelSimulateSensitivity[,{"a"}]

sim["SensitivityNames"]

SystemModelPlot[sim,{{"y","a"},{"z","a"}}]

Show the sensitivity of a signal to relative changes in a parameter:

sim=SystemModelSimulateSensitivity[,5,{"a"}]

Plot bounds for y and z when varying a by 10%:

SystemModelPlot[sim,{{"y","a",0.1},{"z","a",0.1}}]

Use the diagram representation of a model as input:

SystemModel["IntroductoryExamples.ComponentBased.ElectricCircuit"]

Copy and paste the output above:

SystemModelSimulateSensitivity[,5,{"sineVoltage1.freqHz"}]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Simulation Time  (3)

Simulate with settings from the model:

sim=SystemModelSimulateSensitivity[,{"a"}]

sim["SimulationInterval"]

Simulate from time 0 to 5:

sim=SystemModelSimulateSensitivity[,5,{"a"}]

sim["SimulationInterval"]

Simulate for an explicit time interval:

sim=SystemModelSimulateSensitivity[,{2,10},{"a"}]

sim["SimulationInterval"]

OpenersExampleSubsection1(Spacer1)Sensitivity Results  (6)

Study the sensitivity of one parameter:

sim=SystemModelSimulateSensitivity[,50,{"a"}]

sim["SensitivityNames"]

SystemModelPlot[sim,{{"y","a"}}]

Simulate with sensitivity to parameter a:

sim=SystemModelSimulateSensitivity[,5,{"a"}];

Get the sensitivity names:

sim["SensitivityNames"]

Get the sensitivity y has to changes in a:

{ySensA}=sim[{{"y","a"}}]

Study the sensitivities from one parameter:

sim=SystemModelSimulateSensitivity[,5,{"sineVoltage1.freqHz"}];

sim["SensitivityNames"]

Plot one of the sensitivities:

SystemModelPlot[sim,{{"capacitor1.v","sineVoltage1.freqHz"}}]

Show the sensitivity of a signal to a parameter a:

sim=SystemModelSimulateSensitivity[,50,{"a"}]

Get the sensitivity names:

sim["SensitivityNames"]

Get the sensitivity y has to changes in a, as well as the nominal trajectory for y:

{ySensA,y}=sim[{{"y","a"},"y"},t]

Plot y with original parameter a, and with parameter a increased by 0.05:

Plot[{Tooltip[y,"Nominal"],Tooltip[y+0.05 ySensA,"Perturbed"]},{t,0,50}]

Show the sensitivity of a signal to relative changes in a parameter:

sim=SystemModelSimulateSensitivity[,5,{"a"}];

Get the sensitivity names:

sim["SensitivityNames"]

Get the sensitivity y and z have to changes in a, as well as nominal trajectories and value:

{ySensA,zSensA,y,z,a0}=sim[{{"y","a"},{"z","a"},"y","z","a"},t];

Plot bounds for y and z when varying a by 10% of the sensitivity:

{dY,dZ}={a0 0.1ySensA,a0 0.1zSensA};

Plot[{Tooltip[y,"y"],y+dY,y-dY,Tooltip[z,"z"],z+dZ,z-dZ},{t,0,5},Filling->{2->{3},5->{6}}]

Show the sensitivity of a signal to absolute changes in a parameter a:

sim=SystemModelSimulateSensitivity[,50,{"a"}]

Get the sensitivity y has to changes in a, as well as the trajectory for y:

{ySensA,y}=sim[{{"y","a"},"y"},t];

Compute the change in y when parameter a changes with absolute value 0.1:

dY=0.1 ySensA;

Plot the variation of y when parameter a varies by ±0.1:

Plot[{Tooltip[y,"y"],y+dY,y-dY},{t,0,50},Filling->{2->{3}}]

OpenersExampleSubsection2(Spacer1)Variables, Parameters and Inputs  (3)

Change the initial values of a simulation:

(Subscript[sim, 1])=SystemModelSimulateSensitivity[,50,{"a"}];

(Subscript[sim, 2])=SystemModelSimulateSensitivity[,50,{"a"},<|"InitialValues"->{"y"->2.85}|>];

Compare the changes in a plot:

SystemModelPlot[{(Subscript[sim, 1]),(Subscript[sim, 2])},{{"y","a"}}]

Change the parameter values of a simulation:

(Subscript[sim, 1])=SystemModelSimulateSensitivity[,50,{"a"}];

(Subscript[sim, 2])=SystemModelSimulateSensitivity[,50,{"a"},<|"ParameterValues"->{"a"->2.95}|>];

Compare the two in a plot:

SystemModelPlot[{(Subscript[sim, 1]),(Subscript[sim, 2])},{{"y","a"}}]

Give an input function for a variable and study the sensitivity of the output to a gain parameter:

sim=SystemModelSimulateSensitivity[,10,{"gain.k"},<|"Inputs"->{"u"->Sin}|>]

Plot the sensitivity of the output to the gain parameter:

SystemModelPlot[sim,{{"integrator.y","gain.k",0.1}}]

OpenersExampleSubsection3(Spacer1)Result Storage  (1)

Store only selected variables:

sim=SystemModelSimulateSensitivity[,{"y","a"},{"a"}]

Only the given variables and parameters are saved:

{sim["VariableNames"],sim["ParameterNames"]}

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Debug messages are collected in the message group "WSMDebug":

Hold["WSMDebug"]/.$MessageGroups

Turn on debug messages for initialization:

On[SystemModelSimulateSensitivity::dinit]

SystemModelSimulateSensitivity["DocumentationExamples.Basic.OneParameter",{0,1},{"a"}]

Turn off all debug messages for "WSMDebug":

Off["WSMDebug"]

OpenersExampleSection3(Spacer1)Options  (2)

OpenersExampleSubsection4(Spacer1)InterpolationOrder  (1)

Simulate with interpolation orders 1 and 3, and 3 interpolation points:

{(Subscript[sim, 1]),(Subscript[sim, 2])}=Table[SystemModelSimulateSensitivity[,7,{"a"},Method->{Automatic,"InterpolationPoints"->3},InterpolationOrder->intOrder],{intOrder,{1,3}}];

Show the sensitivity variable:

SystemModelPlot[{(Subscript[sim, 1]),(Subscript[sim, 2])},{{"y","a"}}]

OpenersExampleSubsection5(Spacer1)SystemModelProgressReporting  (1)

Control progress reporting with (RefLink[SystemModelProgressReporting, paclet:ref/SystemModelProgressReporting]):

SystemModelSimulateSensitivity[,{"a"},SystemModelProgressReporting->None]

OpenersExampleSection4(Spacer1)Applications  (5)

Study the sensitivity of a model:

sim=SystemModelSimulateSensitivity[,40, {"a"}];

{y,ysensa}=sim[{"y",{"y","a"}},t];

Get the value of the parameter:

a0=First[sim[{"a"}]]

Find the peak deviation when varying the parameter:

{peakVal,{peakTime}}=NMaximize[{0.05 a0 ysensa,0<t<40},{t}]

Show a 5% sensitivity bound and the peak deviation time:

Plot[Evaluate[{y,y+0.05 a0 ysensa,y-0.05 a0 ysensa}],{t,0,40},Filling->{2->{3}},GridLines->{{peakTime[[2]]},None}]

Find out which variable is most sensitive to a frequency parameter:

sim=SystemModelSimulateSensitivity[,1,{"sine.freqHz"}];

A 10% sensitivity bound shows that "integrator3.y" is most sensitive to the parameter:

SystemModelPlot[sim,Table[{v,"sine.freqHz",0.1},{v,{"integrator1.y","integrator2.y","integrator3.y"}}]]

Simulate a rolling wheel:

sim=SystemModelSimulateSensitivity[,10,{"wheel1.wheelRadius","wheel1.wheelMass"}]

Select the position of the wheel and its sensitivities to different parameters:

{x,y,xsensrad,ysensrad,xsensmass,ysensmass}=sim[{"wheel1.x","wheel1.y",{"wheel1.x","wheel1.wheelRadius"},{"wheel1.y","wheel1.wheelRadius"},{"wheel1.x","wheel1.wheelMass"},{"wheel1.y","wheel1.wheelMass"}},t];

{r0,m0}=sim[{"wheel1.wheelRadius","wheel1.wheelMass"}]

Show the path of the wheel with 4% variation of the wheel radius and mass, respectively:

d=0.04;
ParametricPlot[{{x,y},{x+v d #[[1]],y+v d #[[2]]}},{v,-1,1},{t,0,10},PlotPoints->40,Mesh->None,Axes->None,PlotLabel->#[[3]]]&/@{{xsensrad r0,ysensrad r0,"Wheel radius"},{xsensmass m0,ysensmass m0,"Wheel mass"}}

Calibrate parameters in a model by comparing to measurement data:

model=;

data=Import["ExampleData/inertiaTestData.dat"];

{p1,p2,var}={"Resistor1.R","SpringDamper1.d","Inertia2.w"};

Set up caching for simulation:

f[p_?NumericQ,q_?NumericQ]:=f[p,q]=SystemModelSimulate[model,40,<|"ParameterValues"->{p1->p,p2->q}|>][{var}][[1]]

Use (RefLink[SystemModelSimulateSensitivity, paclet:ref/SystemModelSimulateSensitivity]) to get gradients:

g[p_?NumericQ,q_?NumericQ]:=g[p,q]=SystemModelSimulateSensitivity[model,40,{p1,p2},<|"ParameterValues"->{p1->p,p2->q}|>][{{var,p1},{var,p2}}]

Fit parameters to the measurement data:

AbsoluteTiming[pars=FindFit[data,f[p,q][t],{{p,0.1},{q,0.25}},t,Gradient:>Map[#[t]&,g[p,q]]]]

Not using gradients takes longer:

AbsoluteTiming[FindFit[data,f[p,q][t],{{p,0.1},{q,0.25}},t]]

Simulate with the fitted parameters:

sim=SystemModelSimulate[model,{0,40},<|"ParameterValues"->({p1->p,p2->q}/.pars)|>];

Show the test data and the calibrated model together:

Show[SystemModelPlot[sim,{var},PlotStyle->Orange],ListPlot[data]]

SystemModel["DocumentationExamples.Basic.DiffEq"]

Plot a solution with its sensitivity bounds:

sim=SystemModelSimulateSensitivity[,30, {"a"}]

sim["SensitivityNames"]

{y,ysensa}=sim[{"y",{"y","a"} },t];

Get the nominal value of the parameter:

a0=First[sim[{"a"}]]

Show a 5% sensitivity bound:

dY=0.05*a0 ysensa;

Plot[Evaluate[{y,y+dY,y-dY}],{t,0,30},Filling->{2->{3}}]

Simulate with a maximal variation of 5%:

simv=SystemModelSimulate[,30, <|"ParameterValues"->{"a"->a0 Range[0.95,1.05,0.02]}|>];

Get the trajectories:

yV=Table[sd[{"y"},t][[1]],{sd,simv}];

Show that the trajectories are mostly contained in the approximated sensitivity bounds:

Plot[Evaluate[{y,y+dY,y-dY,yV}],{t,0,30},Filling->{2->{3}}]

OpenersExampleSection5(Spacer1)Properties & Relations  (4)

Compare a sensitivity simulation with the sensitivity of the corresponding differential equation:

sim=SystemModelSimulateSensitivity[,50,{"a"}];

SystemModelPlot[sim,{"y",{"y","a"}}]

y=DSolve[{f'[t]+ Sin[a]f[t] == 0, f[0] ==b},f[t],t][[1,1,2]];

ySensA=D[y,a]

Plot[Evaluate[{y,ySensA}/.{a->3,b->1}],{t,0,50},PlotRange->All]

Plot bounds for a relative parameter change:

sim=SystemModelSimulateSensitivity[,5,{"a"}];

Get the sensitivity y has to changes in a, as well as y and the value for a:

{ySensA,y,a0}=sim[{{"y","a"},"y","a"},t];

Plot bounds for y when varying a by 10% of the sensitivity:

dY=a0 0.1ySensA;

Plot[{Tooltip[y,"y"],y+dY,y-dY},{t,0,5},Filling->{2->{3}},AxesLabel->{"t",None}]

Use (RefLink[SystemModelPlot, paclet:ref/SystemModelPlot]) instead:

SystemModelPlot[sim,{{"y","a",0.1}}]

Sensitivities are valid for small changes in the parameter:

{par,var}={"sineVoltage1.freqHz","capacitor1.v"};

Get sensitivities to a parameter:

sim=SystemModelSimulateSensitivity[,5,{par}];

Simulate with ±10% variation of the parameter:

{p0}=sim[{par}];

sim2=SystemModelSimulate[,5,<|"ParameterValues"->{par->{0.9p0,1.1p0}}|>];

Comparing in a plot, a 10% variation gives trajectories outside computed bounds:

Show[SystemModelPlot[sim,{{var,par,0.1}},{2.5,3.5}],SystemModelPlot[sim2,{var}]]

Use (RefLink[SystemModelParametricSimulate, paclet:ref/SystemModelParametricSimulate]) for a function that can be evaluated for different values:

sols=SystemModelParametricSimulate[,"capacitor1.v",{"sineVoltage1.freqHz"}]

Compute solutions for different values of the frequency parameter:

fns=Table[sols[hz],{hz,1,5}]

Plot the solutions over time:

Table[Plot[fn[t],{t,0,10}],{fn,fns}]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Show sensitivity bounds for the x and y axes in the Rabinovich–Fabrikant equations:

sim=SystemModelSimulateSensitivity[,100,{"a","g"},<|"ParameterValues"->{"a"->0.01,"g"->0.05}|>];

{x,y,z,dx,dy,dz}=sim[{"x","y","z",{"x","a"},{"y","a"},{"z","a"}},t];

d=0.04;
ParametricPlot[{x+v d dx,y +v  d dy},{v,0,1},{t,0,19},PlotPoints->40,Axes->None,ColorFunction->ColorData["HypsometricTints"],Mesh->False]

Show the sensitivity bounds in 3D:

Graphics3D[Tube@@Transpose@Table[{{x,y,z},0.0005Norm[{dx,dy,dz}]},{t,10,55,0.05}],Axes->True]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SystemModelSimulate, paclet:ref/SystemModelSimulate])  ▪  (RefLink[SystemModelSimulationData, paclet:ref/SystemModelSimulationData])  ▪  (RefLink[SystemModelExamples, paclet:ref/SystemModelExamples])  ▪  (RefLink[SystemModelParametricSimulate, paclet:ref/SystemModelParametricSimulate])  ▪  (RefLink[ParametricNDSolveValue, paclet:ref/ParametricNDSolveValue])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[System Model Simulation, paclet:guide/SystemModelSimulation])}, {▪(RefLinkPlain[System Model Analytics & Design, paclet:guide/SystemModelAnalyticsDesign])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(Spacer1)▪(WebLink[(Spacer1)Wolfram SystemModeler Documentation, http://reference.wolfram.com/system-modeler/])}})}})