linearize

Linear approximation of Simulink model or block

Syntax

```linsys = linearize(sys,io)linsys = linearize(sys,op)linsys = linearize(sys,op,io)linsys = linearize(sys,op,io,options)linsys = linearize(sys,io,param)[linsys,op] = linearize(sys,io,tsnapshot)linsys = linearize(sys,op,io,'StateOrder',stateorder)linblock = linearize(sys,blockpath,op)linsys = linearize(sys,blocksub,op,io)```

Description

`linsys = linearize(sys,io)` linearizes the nonlinear Simulink® model defined by the linearization I/O points `io`. Linearization uses the operating point that corresponds to the initial states and input levels in the Simulink model.

`linsys = linearize(sys,op)` linearizes the entire Simulink model such that the linearization I/O points are the root-level inport and output blocks in `sys`. Linearization uses the operating point `op`.

`linsys = linearize(sys,op,io)` linearizes the model specified by linearization I/O points `io`.

`linsys = linearize(sys,op,io,options)` uses algorithm options specified in `options`.

`linsys = linearize(sys,io,param)` batch linearizes the model using the specified I/O points, varying the values of the parameters specified by `param`. Linearization uses the operating point that corresponds to the initial states and input levels in the Simulink model.

```[linsys,op] = linearize(sys,io,tsnapshot)``` linearizes the model at one or more simulation times `tsnapshot`. Returns the operating point `op` that corresponds to the simulation snapshot. Omit `io` when you want to use the root-level inport and output blocks in `sys` as linearization I/O points.

`linsys = linearize(sys,op,io,'StateOrder',stateorder)` returns a linear model with a specified state order.

`linblock = linearize(sys,blockpath,op)` linearizes the block in the model `sys` specified by the `blockpath`. Linearization uses the operating point `op`.

`linsys = linearize(sys,blocksub,op,io)` linearizes the nonlinear Simulink model defined by the linearization I/O points `io`. `blocksub` specifies substitute linearizations of blocks and subsystems. Use this syntax, for example, to specify a custom linearization for a block. You can also use this syntax for blocks that do not linearize successfully, such as blocks with discontinuities or triggered subsystems. Omit the operating point `op` when you want to use the model operating point. Omit `io` when you want to use the root-level inport and output blocks in `sys` as linearization I/O points.

Input Arguments

 `sys` Simulink model name, specified as a string inside single quotes (`' '`). `io` Linearization I/O object, specified using `linio`. If the linearization input and output points are annotated in the Simulink model, extract these points from the model into `io` using `getlinio`. `io` must correspond to the Simulink model `sys` or some normal mode model reference in the model hierarchy. `op` Operating point object, specified using `operpoint` or `findop`. `op` must correspond to the Simulink model `sys`. `options` Algorithm options, specified using `linearizeOptions`. `param` Parameter variations, specified as: Structure — For a single parameter, `param` must be a structure with the following fields:`Name` — Parameter name, specified as a string or MATLAB® expression`Value` — Parameter sample values, specified as a double arrayFor example:```param.Name = 'A'; param.Value = linspace(0.9*A,1.1*A,3);```Structure array — Vary the value of multiple parameters. For example, suppose you want to vary the value of the `A` and `b` model parameters in the 10% range:```[A_grid,b_grid] = ndgrid(linspace(0.9*A,1.1*A,3),... linspace(0.9*b,1.1*b,3)); params(1).Name = 'A'; params(1).Value = A_grid; params(2).Name = 'b'; params(2).Value = b_grid;``` If `param` specifies tunable parameters, the software batch linearizes the model using a single model compilation. `tsnapshot` Simulation snapshot time instants when to linearize the model, specified as a scalar or vector. `stateorder` State order in linearization results, specified as a cell array of block paths for blocks with states. Each block path is string of the form model/subsystem/block that uniquely identifies a block in the model. The order of the block paths in the cell array should match the desired order of the linearized model states. `blockpath` Block to linearize, specified as a full block path. A block path is string of the form model/subsystem/block that uniquely identifies a block in the model. `blocksub` Substitute linearizations for blocks and model subsystems. Use `blocksub` to specify a custom linearization for a block or subsystem. You also can use `blocksub` for blocks that do not have analytic linearizations, such as blocks with discontinuities or triggered subsystems. Specify multiple substitute linearizations for a block to obtain a linearization for each substitution (batch linearization). Use this functionality, for example, to study the effects of varying the linearization of a Saturation block on the model dynamics. `blocksub` is an n-by-1 structure, where n is the number of blocks for which you specify the linearization. `blocksub` has these fields: `Name` — Block path corresponding to the block for which you want to specify the linearization.`blocksub.Name` is a string of the form model/subsystem/block that uniquely identifies a block in the model.`Value` — Desired linearization of the block, specified as one of the following:Double, for example `1`. Use for SISO models only. For models having either multiple inputs or multiple outputs, or both, use an array of doubles. For example, ```[0 1]```. Each array entry specifies a linearization for the corresponding I/O combination.LTI model, uncertain state-space model (requires Robust Control Toolbox™ software), or uncertain real object (requires Robust Control Toolbox software). Model I/Os must match the I/Os of the block specified by `Name`. For example, `zpk([],[-10 -20],1)`.Array of LTI models, uncertain state-space models, or uncertain real objects. For example, ```[zpk([],[-10 -20],1); zpk([],[-10 -50],1)]```.If you vary model parameter values, then the LTI model array size must match the grid size.Structure, with the following fields (for information about each field, click the field name)

Output Arguments

 `linsys` Linear time-invariant state-space model that approximates the nonlinear model specified by linearization I/O points `io`. `linsys` is returned as an `ss` object. `op` Operating point corresponding the simulation snapshot of the states and input levels at `tsnapshot`, returned as an operating point object. This is the same object as returned using `operpoint` or `findop`. View `op` values to determine whether the model was linearized at a reasonable operating point. `linblock` Linear time-invariant state-space model that approximates the specified nonlinear block, returned as an `ss` object.

Examples

Linearization at Model Operating Point

This example shows how to use `linearize` to linearize a model at the operating point specified in the model. The model operating point consists of the model initial state values and input signals.

```sys = 'watertank'; load_system(sys); open_system(sys)```

The Water-Tank System block represents the plant in this control system and contains all of the system nonlinearities.

2. Specify to linearize the Water-Tank System block using linearization I/O points.

```sys_io(1)=linio('watertank/PID Controller',1,'input'); sys_io(2)=linio('watertank/Water-Tank System',1,'openoutput');```

Each linearization I/O point is associated with a block outport. For example, to specify a linearization input point at the Water-Tank System block input, you must associate this input point with the outport of the PID Controller block.

`sys_io` is an object array that includes two linearization I/O objects. The first object, `sys_io(1)`, specifies the linearization input point on the first ```watertank/PID Controller``` output signal. The second object, `sys_io(2)`, specifies the linearization output point on the first ```watertank/Water-Tank System``` output signal.

 Note:   When there are multiple block output signals and you want to specify an output port other than the first output, enter the desired output port number as the second argument of `linio`.

Specifying the linearization output point as open loop removes the effects of the feedback signal on the linearization without changing the model operating point.

 Note:   Do not open the loop by manually removing the feedback signal from the model. Removing the signal manually changes the operating point of the model.
3. Update the model to reflect the modified linearization I/O object.

`setlinio(sys,sys_io);`

When you add input points, output points, or loop openings, linearization I/O markers appear in the model. Use these to visualize your linearization points.

4. Linearize the Water-Tank System block at the model operating point.

```linsys = linearize(sys,sys_io); bdclose(sys);```

`linsys` is a state-space model object.

5. Plot a Bode plot of the linearized model.

`bode(linsys)`

The resulting Bode plot looks like a stable first-order response, as expected.

Linearization at Simulation Snapshot

This example shows how to use `linearize` to linearize a model by simulating the model and extracting the state and input levels of the system at specified simulation times.

```sys = 'watertank'; load_system(sys); ```

The Water-Tank System block represents the plant in this control system and contains all of the system nonlinearities.

2. Simulate the model to determine the time when the model reaches steady state.

The Scope block shows that the system reaches steady state at approximately 20 time units.

3. Specify to linearize the open-loop Water-Tank System.

```sys_io(1)=linio('watertank/PID Controller',1,'input'); sys_io(2)=linio('watertank/Water-Tank System',1,'openoutput');```

The last input argument for computing `sys_io(2)` opens the feedback loop.

 Note:   Do not open the loop by manually removing the feedback signal from the model. Removing the signal manually changes the operating point of the model.
4. Linearize the Water-Tank System block at a simulation time of 20time units.

```tsnapshot = 20; linsys = linearize(sys,sys_io,tsnapshot); bdclose(sys);```

`linsys` is a state-space model object.

5. Plot a Bode plot of the linearized model.

`bode(linsys)`

The resulting Bode plot looks like a stable first-order response, as expected.

Linearization at Trimmed Operating Point

This example shows how to use `linearize` to linearize a model using a trimmed operating point.

```sys = 'watertank'; load_system(sys);```
2. Create operating point specification object.

`opspec = operspec(sys);`

By default, all model states are specified to be at steady state.

3. Find the steady-state operating point using trim analysis.

```op = findop(sys,opspec); ```
4. Specify to linearize the open-loop Water-Tank System.

```sys_io(1)=linio('watertank/PID Controller',1,'input'); sys_io(2)=linio('watertank/Water-Tank System',1,'openoutput');```
5. Linearize the Water-Tank System block at the trimmed operating point.

```linsys = linearize(sys,op,sys_io); bdclose(sys);```

`linsys` is a state-space model object.

Linearization at Multiple Simulation Snapshots

This example shows how to use `linearize` to linearize a model at multiple simulation snapshots.

```sys = 'watertank'; load_system(sys);```
2. Specify to linearize the open-loop Water-Tank System.

```sys_io(1)=linio('watertank/PID Controller',1,'input'); sys_io(2)=linio('watertank/Water-Tank System',1,'openoutput');```
3. Define the simulation times at which to linearize the model.

```tsnapshot = [1,20]; linsys = linearize(sys,sys_io,tsnapshot); bdclose(sys);```
4. Plot the Bode response.

`bode(linsys);`

Plant Linearization at Model Operating Point

This example shows how to use `linearize` to linearize a subsystem at the model operating point.

Use this approach instead of defining linearization I/O points when the plant is a subsystem or a block.

```sys = 'watertank'; load_system(sys); blockpath = 'watertank/Water-Tank System';```
2. Linearize the Water-Tank System block.

```linsys = linearize(sys,blockpath); bdclose(sys);```

Alternatives

As an alternative to the `linearize` function, linearize models using:

collapse all

Algorithms

By default, `linearize` automatically sets the Simulink model properties:

• `BufferReuse = 'off'`

• `RTWInlineParameters = 'on'`

• `BlockReductionOpt = 'off'`

After the linearization completes, Simulink restores the original model properties.