## Specify D-Matrix System for Block Linearization Using Function

This example shows how to specify custom linearization for a saturation block using a function.

```sys = 'configSatBlockFcn'; open_system(sys)``` In this model, the limits of the saturation block are `-satlimit` and `satlimit`. The current value of the workspace variable `satlimit` is 10.

2. Linearize the model at the model operating point using the linear analysis points defined in the model. Doing so returns the linearization of the saturation block.

```io = getlinio(sys); linsys = linearize(sys,io)```
```linsys = D = Constant Saturation 1 Static gain. ```

At the model operating point, the input to the saturation block is 10. This value is right on the saturation boundary. At this value, the saturation block linearizes to 1.

3. Suppose that you want the block to linearize to a transitional value of 0.5 when the input falls on the saturation boundary. Write a function that defines the saturation block linearization to behave this way. Save the function to the MATLAB® path.

```function blocklin = mySaturationLinearizationFcn(BlockData) % This function customizes the linearization of a saturation block % based on the block input signal level, U: % BLOCKLIN = 0 when |U| > saturation limit % BLOCKLIN = 1 when |U| < saturation limit % BLOCKLIN = 1/2 when U = saturation limit % Get saturation limit. satlimit = BlockData.Parameters.Value; % Compute linearization based on the input signal % level to the block. if abs(BlockData.Inputs(1).Values) > satlimit blocklin = 0; elseif abs(BlockData.Inputs(1).Values) < satlimit blocklin = 1; else blocklin = 1/2; end```

This configuration function defines the saturation block linearization based on the level of the block input signal. For input values outside the saturation limits, the block linearizes to zero. Inside the limits, the block linearizes to 1. Right on the boundary values, the block linearizes to the interpolated value of 0.5. The input to the function, `BlockData`, is a structure that the software creates automatically when you configure the linearization of the Saturation block to use the function. The configuration function reads the saturation limits from that data structure.

4. In the Simulink model, right-click the Saturation block, and select Linear Analysis > Specify Selected Block Linearization.

The Block Linearization Specification dialog box opens.

5. Check Specify block linearization using one of the following. Choose Configuration Function from the list.

Configure the linearization function:

1. Enter the name you gave to your saturation function. In this example, the function name is `mySaturationLinearizationFcn`.

2. Specify the function parameters. `mySaturationLinearizationFcn` requires the saturation limit value, which the user must specify before linearization.

Enter the variable name `satlimit` in Parameter Value. Enter the corresponding descriptive name in the Parameter Name column, `SaturationLimit`.

3. Click . Configuring the Block Linearization Specification dialog box updates the model to use the specified linearization function for linearizing the Saturation Block. Specifically, this configuration automatically populates the `Parameters` field of the `BlockData` structure, which is the input argument to the configuration function.

### Note

You can add function parameters by clicking . Use to delete selected parameters.

6. Define the saturation limit, which is a parameter required by the linearization function of the Saturation block.

`satlimit = 10;`
7. Linearize the model again. Now, the linearization uses the custom linearization of the saturation block.

`linsys_cust = linearize(sys,io)`
```linsys_cust = d = Constant Saturation 0.5 Static gain. ```

At the model operating point, the input to the saturation block is 10. Therefore, the block linearizes to 0.5, the linearization value specified in the function for saturation boundary.

## Related Topics 