You are on page 1of 21

Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Algebraic Loops
Algebraic Loop Concepts
In a Simulink® model, an algebraic loop occurs when a signal loop exists with only direct feedthrough blocks within
the loop. Direct feedthrough means that Simulink needs the value of the block’s input signal to compute its output at
the current time step. Such a signal loop creates a circular dependency of block outputs and inputs in the same
time-step. This results in an algebraic equation that needs solving at each time-step, adding computational cost to
the simulation.

Some examples of blocks with direct feedthrough inputs are:

• Math Function
• Gain
• Product
• State-Space, when the D matrix coefficient is nonzero
• Sum
• Transfer Fcn, when the numerator and denominator are of the same order
• Zero-Pole, when the block has as many zeros as poles

Nondirect feedthrough blocks maintain a State variable. Two examples are Integrator and Unit Delay.

Tip
To determine if a block has direct feedthrough, read the Characteristics section of the block reference
page.

The figure shows an example of an algebraic loop. The Sum block is an algebraic variable that is constrained to
equal the first input minus (for example, ).

The solution of this simple loop is .

Mathematical Interpretation
Simulink contains a suite of numerical solvers for simulating ordinary differential equations (ODEs), which are
systems of equations that you can write as

where is the state vector and is the independent time variable.

Some systems of equations contain additional constraints that involve the independent variable and the state
vector, but not the derivative of the state vector. Such systems are called differential algebraic equations (DAEs),

The term algebraic refers to equations that do not involve any derivatives. You can express DAEs that arise in
engineering in the semi-explicit form

1 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

where:

• f and g can be vector functions.


• The first equation is the differential equation.
• The second equation is the algebraic equation.
• The vector of differential variables is x.
• The vector of algebraic variables is xa.

In Simulink models, algebraic loops are algebraic constraints. Models with algebraic loops define a system of
differential algebraic equations. Simulink solves the algebraic equations (the algebraic loop) numerically for at
each step of the ODE solver.

The model in the figure is equivalent to this system of equations in semi-explicit form:

At each step of the ODE solver, the algebraic loop solver must solve the algebraic constraint for before
calculating the derivative .

Physical Interpretation
Algebraic constraints:

• Occur when modeling physical systems, often due to conservation laws, such as conservation of mass and
energy
• Occur when you choose a particular coordinate system for a model
• Help impose design constraints on system responses in a dynamic system

Use Simscape™ to model systems that span mechanical, electrical, hydraulic, and other physical domains as
physical networks. Simscape constructs the DAEs that characterize the behavior of a model. The software
integrates these equations with the rest of the model and then solves the DAEs directly. Simulink solves the
variables for the components in the different physical domains simultaneously, avoiding problems with algebraic
loops.

Artificial Algebraic Loops


An artificial algebraic loop occurs when an atomic subsystem or Model block causes Simulink to detect an algebraic
loop, even though the contents of the subsystem do not contain a direct-feedthrough from the input to the output.
When you create an atomic subsystem, all Inport blocks are direct feedthrough, resulting in an algebraic loop.

Start with this model which represents a simple proportional control of the Plant described by .

Rewriting in state-space form:

2 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

The system has neither algebraic variables nor direct feedthrough and does not contain an algebraic loop.

Modify the model as described in the following steps:

1. Enclose the Controller and Plant blocks in a subsystem.


2. In the subsystem block dialog box, select Treat as atomic unit to make the subsystem atomic. For more
information, see Atomic subsystems
3. In the Diagnostics pane of Model Configuration Parameters, set the Algebraic loop parameter to error.

When simulating this model, an algebraic loop occurs because the subsystem is direct feedthrough, even though
the path within the atomic subsystem is not direct feedthrough. Simulation stops with an algebraic loop error.

How the Algebraic Loop Solver Works


When a model contains an algebraic loop, Simulink uses a nonlinear solver at each time step to solve the algebraic
loop. The solver performs iterations to determine the solution to the algebraic constraint, if there is one. As a result,
models with algebraic loops can run more slowly than models without algebraic loops.

Simulink uses a dogleg trust region algorithm to solve algebraic loops. The tolerance used is smaller than the ODE
solver Reltol and Abstol. This is because Simulink uses the “explicit ODE method” to solve Index-1 differential
algebraic equations (DAEs).

For the algebraic loop solver to work,

• There must be one block where the loop solver can break the loop and attempt to solve the loop.
• The model should have real double signals.
• The underlying algebraic constraint must be a smooth function

For example, suppose your model has a Sum block with two inputs—one additive, the other subtractive. If you feed
the output of the Sum block to one of the inputs, you create an algebraic loop where all of the blocks include direct
feedthrough.

The Sum block cannot compute the output without knowing the input. Simulink detects the algebraic loop, and the
algebraic loop solver solves the loop using an iterative loop. In the Sum block example, the software computes the
correct result this way:

( ) = ( ) / 2. (1)

The algebraic loop solver uses a gradient-based search method, which requires continuous first derivatives of the
algebraic constraint that correspond to the algebraic loop. As a result, if the algebraic loop contains discontinuities,
the algebraic loop solver can fail.

3 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

For more information, see Solving Index-1 DAEs in MATLAB and Simulink [1]

Trust-Region and Line-Search Algorithms in the Algebraic Loop Solver. The Simulink algebraic loop solver
uses one of two algorithms to solve algebraic loops:

• Trust-Region
• Line-Search

By default, the algebraic loop solver uses the trust-region algorithm.

If the algebraic loop solver cannot solve the algebraic loop with the trust-region algorithm, try simulating the model
using the line-search algorithm.

To switch to the line-search algorithm, at the MATLAB® command line, enter:

set_param(model_name, 'AlgebraicLoopSolver', 'LineSearch');

To switch back to the trust-region algorithm, at the MATLAB command line, enter:

set_param(model_name, 'AlgebraicLoopSolver', 'TrustRegion');

For more information, see:

• Shampine and Reichelt’s nleqn.m code


• The Fortran program HYBRD1 in the User Guide for MINPACK-1 [2]
• Powell’s “A Fortran subroutine for solving systems in nonlinear equations,” in Numerical Methods for Nonlinear
Algebraic Equations[3]
• Trust-Region Methods for Nonlinear Minimization (Optimization Toolbox).
• Line Search (Optimization Toolbox).

Limitations of the Algebraic Loop Solver. Algebraic loop solving is an iterative process. The Simulink algebraic
loop solver is successful only if the algebraic loop converges to a definite answer. When the loop fails to converge,
or converges too slowly, the simulation exits with an error.

The algebraic loop solver cannot solve algebraic loops that contain any of the following:

• Blocks with discrete-valued outputs


• Blocks with nondouble or complex outputs
• Discontinuities
• Stateflow® charts

Why Algebraic Loops Are Undesirable


If your model contains an algebraic loop:

• You cannot generate code for the model.


• The Simulink algebraic loop solver might not be able to solve the algebraic loop.
• While Simulink is trying to solve the algebraic loop, the simulation can execute slowly.
For most models, the algebraic loop solver is computationally expensive for the first time step. Simulink solves
subsequent time steps rapidly because a good starting point for is available from the previous time step.

Identify Algebraic Loops in Your Model


Use these techniques to search for algebraic loops in your model:

• Use The ashow Debugger Command


• Use The Algebraic Loop Diagnostic
• Highlight Algebraic Loops in the Model

How to Handle Algebraic Loops in a Model


If Simulink reports an algebraic loop in your model, the algebraic loop solver may be able to solve the loop. If

4 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

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


Use 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.

1. Open the model.


2. In the Diagnostics pane of Model Configuration Parameters, set Algebraic loop to none or warning. Setting
this parameter to error prevents the model from compiling.

5 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

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)

The 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 checkbox 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.

Setting Simulation Response

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 sldemo_hydcyl
model.

1. Open the sldemo_hydcyl model.


2. In the Diagnostics pane of the Model Configuration Parameters, set the Algebraic loop parameter to error.
3. 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.

4. Close the Diagnostic Viewer to remove the highlights.


5. Close sldemo_hydcyl model. Do not save the changes.

Use The ashow Debugger Command

6 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Use the ashow command in the Simulink debugger to highlight algebraic loops and step through a simulation.

1. Open the sldemo_hydcyl model.


By default, the Algebraic loop parameter for this model is set to none.
2. Start the Simulink debugger. Select Simulation > Debug > Debug Model.
Run the debugger.
3. In the MATLAB command prompt, enter:
ashow

The command returns the algebraic loop in sldemo_hydcyl and the number of blocks in the loop.
Found 1 Algebraic loop(s):
System number#Algebraic loop id, number of blocks in loop
- 0#1, 9 blocks in loop

4. To list the blocks in this algebraic loop, at the MATLAB command prompt, enter:
ashow 0#1

The Control Valve Flow subsystem in the Valve/Cylinder/Piston/Spring Assembly subsystem opens with the
algebraic loop in the model highlighted. The function lists the nine blocks in the algebraic loop:
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/Control Valve Flow/IC
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/Control Valve Flow/signed sqrt
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/Control Valve Flow/Product
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/laminar flow pressure drop
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/Sum7
- sldemo_hydcyl/Pump/IC
- sldemo_hydcyl/Valve//Cylinder//Piston//Spring Assembly/Control Valve Flow/

Sum1 (algebraic variable)


- sldemo_hydcyl/Pump/Sum1
- sldemo_hydcyl/Pump/leakage (algebraic variable)

Remove Algebraic Loops


Use these techniques to remove algebraic loops in a model.

• Introduce a Delay
• Solve Algebraic Loops Manually
• Create Initial Guesses Using the IC and Algebraic Constraint Blocks

Introduce a Delay
Algebraic loops can occur in large models when atomic subsystems create feedback loops.

In the generic model here, there are two algebraic loops that involve subsystems.

• BlackBox_A —> BlackBox_B —> BlackBox_C —> BlackBox_A


• BlackBox_B —> BlackBox_C —> BlackBox_B

7 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

When you update this model, Simulink detects the loop BlackBox_A —> BlackBox_B —> BlackBox_C —>
BlackBox_A.

Since you do not know the contents of these subsystems, break the loops by adding a Unit Delay block outside the
subsystems. There are three ways to use the Unit Delay block to break these loops:

• Add a Unit Delay between BlackBox_A and BlackBox_C.


• Add a Unit Delay between BlackBox_B and BlackBox_C.
• Add Unit Delay blocks to both algebraic loops.

Add a unit delay between BlackBox_A and BlackBox_C

If you add a unit delay on the feedback signal between the subsystems BlackBox_A and BlackBox_C, you
introduce the minimum number of unit delays (1) to the system. By introducing the delay before BlackBox_A,
BlackBox_B and BlackBox_C use data from the current time step.

Add a unit delay between BlackBox_B and BlackBox_C

If you add a unit delay between the subsystems BlackBox_B and BlackBox_C, you break the algebraic loop
between BlackBox_B and BlackBox_C. In addition, you break the loop between BlackBox_A and BlackBox_C,
because that signal completes the algebraic loop. By inserting the Unit Delay block before BlackBox_C,
BlackBox_C now works with data from the previous time step only.

Add unit delays to both algebraic loops

In the example here, you insert Unit Delay blocks to break both algebraic loops. In this model, BlackBox_A and

8 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

BlackBox_B use data from the previous time step. BlackBox_C uses data from the current time step.

Solve Algebraic Loops Manually


If Simulink cannot solve the algebraic loop, the software reports an error. Use one of these techniques to solve the
loop manually:

• Restructure the underlying DAEs using techniques such as differentiation or change of coordinates. These
techniques put the DAEs in a form that is easier for the algebraic loop solver to solve.
• Convert the DAEs to ODEs, which eliminates any algebraic loops.
• Create Initial Guesses Using the IC and Algebraic Constraint Blocks

Create Initial Guesses Using the IC and Algebraic Constraint Blocks. Your model might contain loops for
which the loop solver cannot converge without a good, initial guess for the algebraic states. You can specify an
initial guess for the algebraic state variables, but use this technique only when you think the loop is legitimate.

There are two ways to specify an initial guess:

• Place an IC block in the algebraic loop.


• Specify an initial guess for a signal in an algebraic loop using an Algebraic Constraint block.

How Simulink Eliminates Artificial Algebraic Loops


When you enable Minimize algebraic loop occurrences, Simulink tries to eliminate artificial algebraic loops. In
this example, the model contains an atomic subsystem that causes an artificial algebraic loop.

The contents of the atomic subsystem are not direct feedthrough, but Simulink identifies the atomic subsystem as
direct feedthrough.

9 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

If the Algebraic loop diagnostic is set to error, simulating the model results in an error because the model
contains an artificial algebraic loop involving its atomic subsystem.

To eliminate this algebraic loop,

1. Create the model from the preceding graphics, with the atomic subsystem that causes the artificial algebraic
loop.
2. In the Diagnostics pane of Model Configuration Parameters, set the Algebraic loop parameter to warning or
none.
3. In the Data Import/Export pane, make sure the Signal logging parameter is disabled. If signal logging is
enabled, Simulink cannot eliminate artificial algebraic loops.
4. To display the sorted order for this model and the atomic subsystem, select Display > Blocks > Sorted
Execution Order.
Reviewing the sorted order can help you understand how to eliminate the artificial algebraic loop.
All the blocks in the subsystem execute at the same level: 1. (0 is the lowest level, indicating the first blocks to
execute.)

10 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Note
For more information about sorted order, see Control and Display the Sorted Order.

5. In the top-level model’s Subsystem Parameters dialog box, select Minimize algebraic loop occurrences.
This parameter directs Simulink to try to eliminate the algebraic loop that contains the atomic subsystem, when
it simulates the model. Save the changes.
6. Click Simulation > Update Diagram to recalculate the sorted order.
Now there are two levels of sorted order inside the subsystem: 1 and 2.

To eliminate the artificial algebraic loop, Simulink tries to make the input of the subsystem or referenced model non-
direct feedthrough.

When you simulate a model, all blocks execute methods in this order:

11 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

1. mdlOutputs
2. mdlDerivatives
3. mdlUpdate

In the original version of this model, the execution of the mdlOutputs method starts with the Plant block because
the Plant block is non-direct feedthrough. The execution finishes with the Controller block.

Note
For more information about these methods, see Block Methods.

If you enable the Minimize algebraic loop occurrences parameter for the atomic subsystem, Simulink divides the
subsystem into two atomic units.

These conditions are true:

• Atomic unit 2 is not direct feedthrough.


• Atomic unit 1 has only a mdlOutputs method.

Only the mdlDerivatives or mdlUpdate methods of Atomic unit 2 need the output of Atomic unit 1. Simulink can
execute what normally would have been executed during the mdlOutput method of Atomic unit 1 in the
mdlDerivatives methods of Atomic unit 2.

The new execution order for the model is:

12 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

1. mdlOutputs method of model


a. mdlOutputs method of Atomic unit 2
b. mdlOutputs methods of other blocks

2. mdlDerivatives method of model


a. mdlOutputs method of Atomic unit 1
b. mdlDerivatives method of Atomic unit 2
c. mdlDerivatives method of other blocks

For the Minimize algebraic loop occurrences technique to be successful, the subsystem or referenced model
must have a non-direct-feedthrough block connected directly to an Inport. Simulink can then set the
DirectFeedthrough property of the block Inport to false to indicate that the input port does not have direct
feedthrough.

Eliminate Artificial Algebraic Loops Caused by Atomic Subsystems


If an atomic subsystem causes an artificial algebraic loop, convert the atomic subsystem to a virtual subsystem.
This change has no effect on the behavior of the model. When the subsystem is atomic and you simulate the
model, Simulink invokes the algebraic loop solver. The solver terminates after one iteration. The algebraic loop is
automatically solved because there is no algebraic constant. After you make the subsystem virtual, Simulink does
not invoke the algebraic loop solver during simulation.

To convert an atomic subsystem to a virtual subsystem:

1. Open the model that contains the atomic subsystem.


2. Right-click the atomic subsystem and select Subsystem Parameters.
3. Clear the Treat as atomic unit parameter.
4. Save the changes.

If you replace the atomic subsystem with a virtual subsystem and the simulation still fails with an algebraic loop
error, examine the model for one of these:

• An algebraic constraint
• An artificial algebraic loop that was not caused by this atomic subsystem

Bundled Signals That Create Artificial Algebraic Loops


Some models bundle signals together. This bundling can cause Simulink to detect an algebraic loop, even when an
algebraic constraint does not exist. If you redirect one or more signals, you may be able to remove the artificial
algebraic loop.

In this example, a linearized model simulates the dynamics of a two-tank system fed by a single pump. In this
model:

• Output q1 is the rate of the fluid flow into the tank from the pump.
• Output h2 is the height of the fluid in the second tank.
• The State-Space block defines the dynamic response of the tank system to the pump operation:

13 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

• The output from the State-Space block is a vector that contains q1 and h2.

If you simulate this model with the Algebraic loop parameter set to warn or error, Simulink identifies the algebraic
loop.

To eliminate this algebraic loop:

1. Change the C and D matrices as follows:

14 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

2. Pass q1 directly to the Scope instead of through the State-Space block.


Now, the input (q1) does not pass directly to the output (the D matrix is 0), so the State-Space block no longer
has direct feedthrough. The feedback signal has only one element now, so the Selector block is no longer
necessary, as you can see in the following model.

Model and Block Parameters to Diagnose and Eliminate Artificial Algebraic Loops
There are two parameters to consider when you think that your model has an artificial algebraic loop:

• Minimize algebraic loop occurrences parameter — Specify that Simulink try to eliminate any artificial
algebraic loops for:
˗ Atomic subsystems — In the Subsystem Parameters dialog box, select Minimize algebraic loop
occurrences.
˗ Model blocks — For the referenced model, in the Model Referencing pane of Configuration Parameters,
select Minimize algebraic loop occurrences.

• Minimize algebraic loop parameter — Specifies what diagnostic action Simulink takes if the Minimize
algebraic loop occurrences parameter has no effect.
The Minimize algebraic loop parameter is in the Diagnostics pane of Configuration Parameters. The

15 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

diagnostic actions for this parameter are:

Setting Simulation Response

none Simulink takes no action.


warning Simulink displays a warning that the Minimize algebraic loop
occurrences parameter has no effect.
error Simulink terminates the simulation and displays an error that the Minimize
algebraic loop occurrences parameter has no effect.

Block Reduction and Artificial Algebraic Loops


When you enable the Block reduction optimization in Model Configuration Parameters, Simulink collapses certain
groups of blocks into a single, more efficient block, or removes them entirely. Enabling block reduction results in
faster execution during model simulation and in generating code.

Enabling block reduction can also help Simulink solve artificial algebraic loops.

Consider the following example model.

Initially, block reduction is turned off. When you simulate this model, the Atomic Unit subsystem and Gain and
Compare to Constant blocks are part of an algebraic loop that Simulink cannot solve.

16 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

If you enable block reduction and sorted order, and resimulate the model, Simulink does not display the sorted
order for blocks that have been reduced. You can now quickly see which blocks have been reduced.

The Compare to Constant and Gain blocks have been eliminated from the model, so they no longer generate an
algebraic loop error. The Atomic Unit subsystem generates a warning:

Warning: If the inport 'ex_aloop_block_reduction_errwarn/


Atomic Unit/In1' of subsystem 'ex_aloop_block_reduction_errwarn/
Atomic Unit' involves direct feedback, then an algebraic loop
exists, which Simulink cannot remove. Consider clearing the
'Minimize algebraic loop occurrences' parameter to avoid this
warning.

17 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Tip
Use Bus Selector blocks to pass only the required signals into atomic subsystems.

When Simulink Cannot Eliminate Artificial Algebraic Loops


Setting the Minimize algebraic loop occurrences parameter does not always work. Simulink cannot change the
DirectFeedthrough property of an Inport for an atomic subsystem if the Inport is connected to an Outport only
through direct-feedthrough blocks.

In this model, the subsystem Plant+Controller causes an algebraic loop, but it has an extra Gain block and an extra
output.

18 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Simulink cannot move the mdlOutputs method of the Controller block to the mdlDerivative method of an Atomic
unit 1 because the output of the atomic subsystem depends on the output of the Controller block. You cannot make
the subsystem non-direct-feedthrough.

You can modify this model to eliminate the artificial algebraic loop by redefining the atomic subsystem by adding
additional Inport and Gain blocks, as you can see in the model here. Doing so makes In1 non-direct-feedthrough
and In2 direct feedthrough, thus breaking the algebraic loop.

Modeling Considerations with Algebraic Loops

Managing Large Models with Artificial Algebraic Loops


Adopt these design techniques for large models with algebraic loops:

• Avoid creating loops that contain discontinuities or nondouble data types. The Simulink algebraic loop solver is
gradient-based and must solve algebraic constraints to high precision.
• Develop a scheme for clearly identifying atomic subsystems as direct feedthrough or not direct feedthrough. Use
a visual scheme such as coloring the blocks or defining a block-naming convention.
• If you plan to generate code for your model, enable the Minimize algebraic loop occurrences parameter for all
atomic subsystems. When possible, make sure that the input ports for the atomic subsystems are connected
directly to non-direct-feedthrough blocks.
• Avoid combining non-direct-feedthrough and direct-feedthrough paths using the Bus Creator or Mux blocks.
Simulink may not be able to eliminate any resulting artificial algebraic loops. Instead, consider clustering the
non-direct-feedthrough and direct-feedthrough objects in separate subsystems.
Use Bus Selector blocks to pass only the required signals into atomic subsystems.

Model Blocks and Direct Feedthrough


When a Model block is part of a cycle, and the block is a direct feed through block, an algebraic loop can result. An
algebraic loop in a model is not necessarily an error, but it can give unexpected results. See:

• Highlight Algebraic Loops in the Model for information about seeing algebraic loops graphically.
• Display Algebraic Loop Information for information about tracing algebraic loops in the debugger.
• The Model Configuration Parameters: Diagnostics pane Algebraic loop option for information on detecting
algebraic loops automatically.

19 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

Direct Model Block Feedthrough Caused by Submodel Structure. A Model block can be a direct feed through
block due to the structure of the referenced model. Where direct feed through results from sub model structure, and
causes an unwanted algebraic loop, you can:

• Automatically eliminate the algebraic loop using techniques described in:


˗ Minimize algebraic loop
˗ Minimize algebraic loop occurrences
˗ Remove Algebraic Loops

• Manually insert the number of Unit Delay blocks needed to break the algebraic loop.

Direct Model Block Feedthrough Caused by Model Configuration. Generic Real Time (grt) and Embedded
Real Time (ert) based targets provide the Single output/update function option on the Configuration
Parameters dialog. This option controls whether generated code has separate output and update functions, or a
combined output/update function. See:

• Configure Code Generation for Model Entry-Point Functions (Simulink Coder) for information about separate
and combined output and update functions.
• Single output/update function (Simulink Coder) for information about specifying whether code has separate or
combined functions.

When Single output/update function is enabled (default), a Model block has a combined output/update function.
The function makes the block a direct feed through block for all inports, regardless of the structure of the referenced
model. Where an unwanted algebraic loop results, you can:

• Disable Single output/update function. The code for the Model block then has separate output and update
functions, eliminating the direct feed through and hence the algebraic loop.
• Automatically eliminate the algebraic loop using techniques described in:
˗ Minimize algebraic loop
˗ Minimize algebraic loop occurrences
˗ Remove Algebraic Loops

• Manually insert one or more Unit Delay blocks as needed to break the algebraic loop.

Changing Block Priorities When Using Algebraic Loop Solver


During the updating phase of simulation, Simulink determines the simulation execution order of block methods. This
block invocation ordering is the sorted order.

If you assign priorities to nonvirtual blocks to indicate to Simulink their execution order relative to other blocks, the
algebraic loop solver does not honor these priorities when attempting to solve any algebraic loops.

See Also
Algebraic Constraint | Descriptor State-Space | Solvers | Zero-Crossing Detection

[1]
Shampine, Lawrence F., M.W.Reichelt, and J.A.Kierzenka. ”Solving Index-1 DAEs in MATLAB and
Simulink.”Siam Review.Vol.18,No.3,1999,pp.538–552.
[2]
More,J.J.,B.S.Garbow, and K.E.Hillstrom. User guide for MINPACK-1. Argonne, IL:Argonne National
Laboratory,1980.
[3]
Rabinowitz, Philip, ed. Numerical Methods for Nonlinear Algebraic Equations, New York: Gordon and Breach
Science Publishers, 1970.

20 of 21 10/8/2018, 9:05 AM
Algebraic Loops - MATLAB & Simulink https://www.mathworks.com/help/simulink/ug/algebraic-loops.html?se...

How useful was this information?

21 of 21 10/8/2018, 9:05 AM

You might also like