You can linearize models with Simscape™ components using Simulink^{®}
Control Design™ software. Typically, some states in a Simscape network have dependencies on other states through constraints.

To find a steady-state operating point at which to linearize a Simscape model, you can use:

Optimization-based trimming — Specify constraints on model inputs, outputs, or states, and compute a steady-state operating point that satisfies these constraints.

To produce better trimming results for Simscape models, you can use projection-based trim optimizers. These optimizers enforce the consistency of the model initial condition at each evaluation of the objective function or nonlinear constraint function.

Simulation snapshots — Specify model initial conditions near an expected equilibrium point, and simulate the model until it reaches steady state.

For more information, see Find Steady-State Operating Points for Simscape Models.

To linearize your model, you must specify the portion of the model you want to linearize using linear analysis points; that is, linearization inputs and outputs, and loop openings. You can only add analysis points to Simulink signals.

To add a linearization input or loop opening to the input of a Simscape component, first convert the Simulink signal using a Simulink-PS Converter block.

To add a linearization output or loop opening to the output of a Simscape component, first convert the Simscape signal using a PS-Simulink Converter block.

For more information on adding linear analysis points, see Specify Portion of Model to Linearize.

After you specify a steady-state operating point and linear analysis points, you can linearize your Simscape model using:

The

**Linear Analysis Tool**.The

`linearize`

function.An

`slLinearizer`

interface.

For general linearization examples, see Linearize Simulink Model at Model Operating Point and Linearize at Trimmed Operating Point.

Simscape networks can commonly linearize to zero when a set of the system equation Jacobians are zero at a given operating condition. Usually, poor initial conditions of the network states cause these zero linearizations.

Consider a system where the mass flow rate from a variable orifice is controlling the position of a piston. The mass flow rate equation of the variable orifice is:

$$q={C}_{d}A\sqrt{\frac{2}{\mu}}{\left(\frac{p}{{p}^{2}+{p}_{cr}^{2}}\right)}^{0.25}$$

Where:

*q*is the mass flow rate.*C*is the discharge coefficient._{d}*A*is the area of the variable orifice opening.*μ*is the fluid density.*p*is the pressure drop across the orifice,*p*=*p*-_{a}*p*._{b}*p*is the critical pressure, which is a function of_{cr}*p*and_{a}*p*._{b}

The control variable for this system is the orifice area, *A*, which
controls the mass flow rate. The Jacobian of the mass flow rate with respect to the
control variable is:

$$\frac{\partial q}{\partial A}={C}_{d}\sqrt{\frac{2}{\mu}}{\left(\frac{p}{{p}^{2}+{p}_{cr}^{2}}\right)}^{0.25}$$

The linearized mass flow rate equation is:

$$\begin{array}{l}\overline{q}={C}_{d}\sqrt{\frac{2}{\mu}}{\left(\frac{p}{{p}^{2}+{p}_{cr}^{2}}\right)}^{0.25}\overline{A}+\frac{\partial q}{\partial \mu}\overline{\mu}\\ +\left(\frac{\partial q}{\partial {p}_{cr}}\frac{\partial {p}_{cr}}{\partial {p}_{a}}+\frac{\partial q}{\partial p}\right){\overline{p}}_{a}+\left(\frac{\partial q}{\partial {p}_{cr}}\frac{\partial {p}_{cr}}{\partial {p}_{b}}-\frac{\partial q}{\partial p}\right){\overline{p}}_{b}\end{array}$$

where $$\overline{\xb7}$$ represents a deviation from the nominal variable.

In the linearized equation, if the nominal pressure drop *p* across
the orifice is zero, then $$\overline{A}$$ has no influence on $$\overline{q}$$. That is, if the instantaneous pressure drop across the orifice is zero,
the orifice area has no influence on the mass flow rate. Therefore, you cannot control the
piston position using the orifice area control variable.

To avoid this condition, linearize the model about an operating point where the
pressure drop over the orifice is nonzero (*p _{a}* ≠

To fix linearization problems caused by poor initial conditions of network states, you can:

Linearize the system at a snapshot operating point or trimmed operating point. When possible, this approach is recommended.

Find and modify the problematic states of the operating point. This option can be difficult for models with many states.

Using the first approach, you can ensure that the model states are consistent via the Simulink and Simscape simulation engine. Simscape initial conditions are not necessarily in a consistent state. The Simscape engine places them in a consistent state during simulation and for trimming using the Simscape trim solvers.

A common workflow is to simulate your model, observe at what time the model satisfies the operating condition at which you want to linearize, then take a simulation snapshot. Alternatively, you can trim the model about the condition you are interested in. In either case, the network states are in a consistent condition, which solves most poor linearization issues.

Using the second approach, you search through the physical network states to find conditions that can create a zero Jacobian. This approach can require some intuition about the dynamics of the physical components in your model. As a starting point, search for states that are zero and that interact directly with nonlinear physical elements, such as the variable orifice in the preceding example.

To search the physical states, you can use the Linearization Advisor, which collects diagnostic information during linearization. The Linearization Advisor does not provide diagnostic information on a component-level basis for Simscape networks. Instead, it groups diagnostic information for multiple Simscape components together.

Linearize your model with the Linearization Advisor enabled, and extract the

`LinearizationAdvisor`

object.`opt = linearizeOptions('StoreAdvisor',true); [linsys,linop,info] = linearize(mdl,io,op,opt); advisor = info.Advisor;`

Create a custom query object, and search the diagnostic information for Simscape blocks.

`qSS = linqueryIsBlockType('simscape'); advSS = find(advisor,qSS);`

To find problematic state values, check the block operating point in each

`BlockDiagnostic`

object.advSS.BlockDiagnostics(i).OperatingPoint.States

Once you find a problematic state, you can change the value of the state in the model
operating point, or create an operating point using `operpoint`

.

You can also search the Linearization Advisor in the Linear Analysis Tool. For more information, see Find Blocks in Linearization Results Matching Specific Criteria.