Using Simulink    

Algebraic Loops

Some Simulink blocks have input ports with direct feedthrough. This means that the output of these blocks cannot be computed without knowing the values of the signals entering the blocks at these input ports. Some examples of blocks with direct feedthrough inputs are as follows:

An algebraic loop generally occurs when an input port with direct feedthrough is driven by the output of the same block, either directly, or by a feedback path through other blocks with direct feedthrough. (See Nonalgebraic Direct-Feedthrough Loops for an example of an exception to this general rule.) An example of an algebraic loop is this simple scalar loop.

Mathematically, this loop implies that the output of the Sum block is an algebraic state z constrained to equal the first input u minus z (i.e. z = u - z). The solution of this simple loop is z = u/2, but most algebraic loops cannot be solved by inspection. It is easy to create vector algebraic loops with multiple algebraic state variables z1, z2, etc., as shown in this model.

The Algebraic Constraint block is a convenient way to model algebraic equations and specify initial guesses. The Algebraic Constraint block constrains its input signal F(z) to zero and outputs an algebraic state z. This block outputs the value necessary to produce a zero at the input. The output must affect the input through some feedback path. You can provide an initial guess of the algebraic state value in the block's dialog box to improve algebraic loop solver efficiency.

A scalar algebraic loop represents a scalar algebraic equation or constraint of the form F(z) = 0, where z is the output of one of the blocks in the loop and the function F consists of the feedback path through the other blocks in the loop to the input of the block. In the simple one-block example shown on the previous page, F(z) = z - (u - z). In the vector loop example shown above, the equations are

Algebraic loops arise when a model includes an algebraic constraint F(z) = 0. This constraint might arise as a consequence of the physical interconnectivity of the system you are modeling, or it might arise because you are specifically trying to model a differential/algebraic system (DAE).

When a model contains an algebraic loop, Simulink calls a loop solving routine at each time step. The loop solver performs iterations to determine the solution to the problem (if it can). As a result, models with algebraic loops run slower than models without them.

To solve F(z) = 0, the Simulink loop solver uses Newton's method with weak line search and rank-one updates to a Jacobian matrix of partial derivatives. Although the method is robust, it is possible to create loops for which the loop solver will not converge without a good initial guess for the algebraic states z. You can specify an initial guess for a line in an algebraic loop by placing an IC block (which is normally used to specify an initial condition for a signal) on that line. As shown above, another way to specify an initial guess for a line in an algebraic loop is to use an Algebraic Constraint block.

Whenever possible, use an IC block or an Algebraic Constraint block to specify an initial guess for the algebraic state variables in a loop.

Nonalgebraic Direct-Feedthrough Loops

There are exceptions to the general rule that all loops comprising direct-feedthrough blocks are algebraic. The exceptions are

A triggered subsystem holds its outputs constant between trigger events (see Triggered Subsystems). Thus, a solver can safely use the output from the system's previous time step to compute its input at the current time step. This is, in fact, what a solver does when it encounters a loop involving a triggered subsystem, thus eliminating the need for an algebraic loop solver.

Consider, for example, the following system.

.

This system effectively solves the equation

where u is the value of z the last time the subsystem was triggered. The output of the system is a staircase function as illustrated by the display on the system's scope.

Now consider the effect of removing the trigger from the system shown in the previous example.

In this case, the input at the u2 port of the adder subsystem is equal to the subsystem's output at the current time step for every time step. The mathematical representation of this system

reveals that it has no mathematically valid solution.

Highlighting Algebraic Loops

You can cause Simulink to highlight algebraic loops when you update, simulate, or debug a model. Use the ashow command to highlight algebraic loops when debugging a model.

To cause Simulink to highlight algebraic loops that it detects when updating or simulating a model, set the Algebraic loop diagnostic on the Diagnostics pane of the Simulation parameters dialog box to Error (see Configuration options for more information). This causes Simulink to display an error dialog (the Diagnostic Viewer) and recolor portions of the diagram that represent the algebraic loops that it detects. Simulink uses red to color the blocks and lines that constitute the loops. Closing the error dialog restores the diagram to its original colors.

For example, he following figure shows the block diagram of the hydcyl demo model in its original colors.

The following figure shows the diagram after updating when the Algebraic loop diagnostic is set to Error.

In this example, Simulink has colored the algebraic loop red, making it stand out from the rest of the diagram.


  Zero-Crossing Detection Modeling and Simulating Discrete Systems