Main Content

Troubleshoot Linearization Results in Model Linearizer

This example shows how to use the Linearization Advisor to debug the linearization of a pendulum model in theModel Linearizer.

Setup Model

Open the Simulink® model.

mdl ='scdpendulum'; open_system(mdl)

The initial condition for the pendulum angle is 90 degrees counterclockwise from the upright unstable equilibrium of 0 degrees. The initial condition for the pendulum angular velocity is 0 deg/s. The nominal torque to maintain this state is -49.05 N m. This configuration is saved as the model initial condition.

Open Model Linearizer and Linearize Model

To openModel Linearizer, in the Simulink model window, on theAppstab, clickModel Linearizer.

To linearize the model at the model initial condition, inModel Linearizer, on theLinear Analysistab, clickBode.

The software linearizes the model and plots its frequency response.

As can be seen from the Bode plot, the system linearizes to zero such that the torque has no effect on the angle or angular velocity. You can explore why this is the case using the Linearization Advisor.

Linearize Model with Advisor Enabled

To relinearize the model and generate an advisor, selectLinearization Advisor, and clickBode Plot 1.

The software linearizes the model, creates thelinsys2_advisordocument, and opens theAdvisortab.

Highlight Linearization Path

To show the linearization path for the current linearization, on theAdvisortab, clickHighlight Linearization Path. In the Simulink model, the blocks highlighted in:

  • Blue numerically influence the model linearization.

  • Red are on the linearization path but do not influence the model linearization for the current operating point and block parameters.

For convenience, only the blocks underneath the pendulum subsystem are shown.

In this case, since the model linearized to zero, there are no blocks that contribute to the linearization.

Investigate Potentially Problematic Blocks Using Advisor

Thelinsys2_advisordocument shows a table listing blocks that may be problematic for the linearization.

To view more information about a specific block linearization, in the corresponding row of the table, clickBlock Info.

In this case, three blocks are reported by the advisor, a Saturation block and two Trigonometric Function blocks. Investigate the Saturation block first since it has diagnostics. To do so, in the first row of the table, clickBlock Info.

There are two diagnostic messages for the Saturation block. The first message indicates that the block is linearized outside of its lower saturation limit of-49, since the input operating point is-49.05. The message also states the block can be linearized as a gain, which will linearize the block as1regardless of the input operating point. To do so, first clicklinearizing the block as a gain, which highlights the corresponding parameter in the block dialog box. Then, select theTreat as gain when linearizingparameter.

The second message states that the linearization of this block causes the model to linearize to zero. As shown in theLinearizationsection, the block is linearized to zero. Therefore, modifying the block linearization is a good first step toward obtaining a nonzero model linearization.

Relinearize Model

After setting the Saturation block to be treated as a gain, relinearize the model. For now, ignore the diagnostics for the two Trigonometric Function blocks.

To relinearize the model, on theLinear Analysistab, clickBode Plot 1. TheBode Plot 1document updates, showing the nonzero response oflinsys3.

In the correspondinglinsys_advisor3document, the Saturation block is no longer listed. However, the two Trigonometric Function blocks are still shown.

Highlight the linearization path.

Most of the blocks are now contributing to the model linearization, except for the paths going through the listed Trigonometric Function blocks.

To understand why these blocks are not contributing to the linearization, navigate to the blocks from thelinsys3_advisordocument. For example, clickBlock Infoin the second row of the table.

For this Trigonometric Function block, the linearization is zero and the input operating point is π / 2 = 1 . 5 7 0 8 .

You can find the linearization of the block analytically by taking the first derivative of thesinfunction with respect to the inputs:

u sin ( u ) = cos ( u )

Therefore, when evaluated at u = π / 2 the linearization of the block is zero. The source of the input is the first output of the second-order integrator, which is dependent upon the stateθ. Therefore, this block will linearize to zero if θ = π / 2 + k π , where k is an integer. The same condition applies for the other Trigonometric Function in the angle_wrap subsystem.

If these blocks are not expected to linearize to zero, you can modify the operating point stateθ, and relinearize the model.

Run Prebuilt Advisor Queries

The Linearization Advisor provides a set of prebuilt queries for filtering block diagnostics. For example, theLinearization Advicequery is the default query run when the advisor is first created and includes blocks on the path that:

  • Have diagnostic messages regarding the block linearization.

  • Linearized to zero.

  • Have substituted linearizations.

To run a different prebuilt query, on theAdvisortab, in theQueriesgallery, click the query. For example, clickZero I/O Pair on Path.

This query returns blocks with linearizations that have output channels that cannot be reached by any input channel, or input channels that have no influence on any output channels. For example, the second block in the table is a Trigonometric Function block configured asatan2. The first input of this block cannot reach the only output.

Create and Run Custom Queries

The Linearization Advisor also provides a Query Builder for creating custom queries. You can use these queries to find blocks in your model that match specific criteria. For example, to find all SISO blocks that are numerically perturbed, first open the Query Builder. To do so, on theAdvisortab, clickNew Query.

In the Query Builder dialog box:

  1. Specify theQuery Nameassisopert.

  2. In the drop-down list, selectHas 'Ny' Outputs', and specify1in theOutputsbox.

  3. To add another component to the query, clickAdd to Query.

  4. In the second drop-down list, selectHas 'Nu' Inputs', and specify1in theInputsbox.

  5. ClickAdd to Query.

  6. In the third drop-down list, selectPerturbation.

ClickRun Query.

Thelinsys3_advisordocument shows the blocks that match the specified query criteria, and thesisopertquery is added to theQueriesgallery.

To remove thesisopertquery, on the Advisor tab, clickRemove Query, and selectsisopert.

Export Advisor and Generate MATLAB Script

You can also debug model linearizations using the Linearization Advisor command-line functions. To export the advisor object to the MATLAB® workspace, clickExport. Then, in the Export Advisors dialog box, select one or more advisors to export. For example, selectlinsys3_advisor.

ClickExport.

Alternatively, you can generate a MATLAB script that automates the linearization, extraction of the advisor, generation of custom queries, and running of queries. To generate this script, click theExportsplit button, then selectGenerate Script.

bdclose(mdl)

See Also

Apps

Related Topics