Main Content

Identify Algebraic Loops in Your Model

If Simulink®reports an algebraic loop in your model, the algebraic loop solver may be able to solve the loop. If Simulink cannot solve the loop, there are several techniques to eliminate the loop.

Use this workflow to decide how you want to eliminate an algebraic loop.

Highlight Algebraic Loops in the Model

UsegetAlgebraicLoopsto identify algebraic loops in a model and highlight them in the Simulink Editor. With this approach:

  • You can traverse multiple layers of model hierarchy to locate algebraic loops.

  • You can identify real and artificial algebraic loops.

  • 您可以同时在模型中可视化所有循环。

  • You do not need to drill in and out of the model, across boundaries.

  • You do not need to detect loops in serial order. Also, you do not need to compile the model every time you detect and solve a loop. Therefore you can solve loops quickly.

您在整个型号上执行突出显示的代数循环,而不是特定子系统。

  1. Open the model.

  2. 在里面Diagnosticspane of Model Configuration Parameters, setAlgebraic looptonone或者warning. Setting this parameter to错误prevents the model from compiling.

  3. Compile the model without any errors. The model must compile before you can highlight any algebraic loops.

  4. At the MATLAB®command prompt, enter:

    Simulink.BlockDiagram.getAlgebraicLoops(bdroot)

ThegetAlgebraicLoopsfunction highlights algebraic loops in the model, including algebraic loops in subsystems. It also creates a report with information about each loop:

  • Solid lines represent real algebraic loops.

  • Dotted lines represent artificial algebraic loops.

  • A red highlight appears around a block assigned with an algebraic variable.

  • The循环IDhelps you identify the system that contains a particular loop.

Customize the report by selecting or clearing theVisiblecheck box for a loop.

一旦在模型中识别了代数循环,就可以通过编辑模型来删除它们。关闭突出显示报告并更改模型。只有关闭报告后,才能编辑模型。

Simulink does not save loop highlighting. Closing the model or exiting the display removes the loop highlighting.

Use the Algebraic Loop Diagnostic

Simulink detects algebraic loops during simulation initialization, for example, when you update your diagram. You can set the Algebraic loop diagnostic to report an error or warning if the software detects any algebraic loops in your model.

在里面Diagnostics面板模型的Configuration Parameters, set theAlgebraic loopparameter:

  • none-- Simulink tries to solve the algebraic loop; reports an error only if the algebraic loop cannot be solved.

  • warning-- Algebraic loops result in warnings. Simulink tries to solve the algebraic loop; reports an error only if the algebraic loop cannot be solved.

  • 错误- 代数循环停止初始化。在Simulink尝试解决循环之前,手动查看循环。金宝app

This example shows how to use the algebraic loop diagnostic to highlight algebraic loops in theSLDEMO_HYCYL.model.

  1. Open theSLDEMO_HYCYL.model

  2. 在里面Diagnostics面板模型的Configuration Parameters, set theAlgebraic loopparameter to错误.

  3. 尝试模拟模型

当Simu金宝applink在初始化期间检测到代数循环时,模拟停止。诊断查看器显示错误消息,并列出模型中的所有块,该模型是该代数循环的一部分。在模型中,红色亮点显示构成循环的块和信号。

To remove the highlights, close the Diagnostic Viewer.

相关话题