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
getAlgebraicLoops to 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 can visualize all loops in your model simultaneously.
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.
You perform algebraic loop highlighting on an entire model, not on specific subsystems.
Open the model.
In the Diagnostics pane of Model Configuration Parameters, set Algebraic loop to
warning. Setting this parameter to
errorprevents the model from compiling.
Compile the model without any errors. The model must compile before you can highlight any algebraic loops.
At the MATLAB® command prompt, enter:
getAlgebraicLoops function 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 Loop ID helps you identify the system that contains a particular loop.
Customize the report by selecting or clearing the Visible check box for a loop.
Once you have identified algebraic loops in a model, you can remove them by editing the model. Close the highlight report and make changes to the model. You can edit the model only after you close the report.
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.
In the Diagnostics pane of the Model Configuration Parameters, set the Algebraic loop parameter:
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.
error-- Algebraic loops stop the initialization. Review the loop manually before Simulink tries to solve the loop.
This example shows how to use the algebraic loop diagnostic to highlight algebraic loops in the
In the Diagnostics pane of the Model Configuration Parameters, set the Algebraic loop parameter to
Try to simulate the model
When Simulink detects an algebraic loop during initialization, the simulation stops. The Diagnostic Viewer displays an error message and lists all the blocks in the model that are part of that algebraic loop. In the model, red highlights show the blocks and signals that make up the loop.
To remove the highlights, close the Diagnostic Viewer.