Seth on Simulink
July 3rd, 2008
How did I get an algebraic loop error, when the diagnostic was set to warning?
I once faced a problem where Simulink reported, “Cannot solve algebraic loops...”

Algebraic
loops can be solved by Simulink, but often slow down the simulation. For
this reason, we have the algebraic
loop diagnostic that can be set to Error, Warning or None.
What was peculiar about this model was that the algebraic loop diagnostic was
set to Warning, yet the model would report an error, and not simulate! To
makes things more difficult, all I had to work with was a screen shot of the
model, not the model it self.
What are algebraic loops?
Algebraic loops exist when a variable shows up on both sides of the equation. For
example,

Algebraic loops generally occur in Simulink when there are un-modeled delays, for
example, sensors that just feed through a signal from input to output.
Read the error message
The first step in debugging a problem like this is to read and understand the error
message. Algebraic loop errors occur for different reasons. To understand the
cause of the error I had to understand the message.
Cannot solve algebraic loop involving 'model/.../Sensor System' because it consists of blocks that
cannot be assigned algebraic variables, i.e., blocks with discrete-valued
outputs, blocks with non-double or complex outputs, Stateflow blocks, or nonvirtual
subsystems.
Picking apart this message, we learn that Simulink cannot solve algebraic loops unless
it can assign an algebraic variable. The blocks that cannot be assigned
algebraic variables are listed in the error.
- Discrete-valued outputs, like logic blocks [0 or 1]
- Blocks that have non-double outputs
- Blocks that output complex values (3+2i)
- Stateflow blocks
- Nonvirtual subsystems
Figure out how the message relates to the model
Next, I looked at the screen shot and see if I could find those blocks. This is roughly
similar to the screen shot sent to technical support:

The first thing I noticed was that all the signals are of type uint8. Those are
non-double types, so that could be part of the problem. Another thing I
noticed was the heavy lines on the subsystems. That means these are atomic
subsystems. Atomic subsystems are nonvirtual, and those are on the list of
blocks that could cause this problem.
Possible Resolution
Because
these were atomic subsystems, I suggested enabling the Minimize
algebraic loop occurrences optimization.

The
subsystem can be thought of a function of its inputs and states

In some systems, the output signal calculations do not directly rely on the inputs.
If this is true, you can separate the system into two equations.


This option is also available for model
reference blocks through the configuration parameters on the Model
Referencing entry.
How did this happen?
This model was the result of integrating components from many different teams. The
original model contained virtual subsystems, and the new components used to
upgrade the model were atomic subsystems. Switching back to virtual might have
resolved this error also.
The algebraic loop diagnostic did not control this error because this was part of
the check for the minimum solvability requirements for this type of problem.
Now it’s your turn
There is additional information in the technical support solutions on
understanding algebraic loops, and how
does Simulink solve them. Have you encountered this error? How did you work
around it? Leave a comment
here about your experience.
21:30 UTC |
Posted in Debugging, Modeling |
Permalink |
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
I have that same problem and i have not find out out to solve it. I would hope that simulink would just do come kind of finite differences to work it out but no. I have even tried to make a discretization of the model without success.
Good luck.
Seth,
Dealing with algebraic loops is by far the most frustrating problem in simulink. It seems to me that there are two types of algebraic loops. The first is the mathematical type, e.g. y = 2-y as in your example. These are usually easy to understand and deal with if we don’t want the solver to solve them. The other type, however, are apparent algebraic loops found by the solver because of how it treats atomic subsystems, embedded matlab function blocks, model references, etc. This type is not really discussed all that well in the documentation. Most, but not all, of the problems I’ve had involve models with these types of blocks, and in these cases the “minimize algebraic loop occurences” hasn’t worked for me. I’ve had problems where the red highlighting of the algebraic loop stops in midstream and I can’t determine where the problem is; I had a case where an algebraic loop was reported when a gain block was set to something other than 1; and I just had a problem where an algebraic loop error was reported in a very simple model, without any atomic subsystems or embedded function blocks. In this particular case, I had an algebraic loop error when I passed a width-3 signal output from a virtual subsystem through a demux, but didn’t have an error when I passed out the 3-signals individually. In this same model, I also had an algebraic loop error when I put a gain block (with gain=1) onto a line, but didn’t have any problems w/o the gain block. This kind of stuff is very frustrating. A similar problem is with enabled subsystems where the enabling signal is dependent of the states of the subsystem. For example, consider two balls moving on a wire and we want to disable them when they collide. I’ve yet to figure out how to do this w/o putting an extra memory block into the system, outside of the enabled subsystems that govern the motion of the balls, which allows the balls to continue to move for one time step after they’ve collided. Thanks for the forum for this rant. Keep up the blog; I’ve been finding it very interesting.
@Pedro - Simulink does uses Newton’s method to perform a search for the solution. If you have trouble getting it to converge, note the algebraic variable, and place an IC block (initial condition) at the output port of that block. You can then provide an initial guess for the solver, and may improve your results. The result from the last solution is used as the initial guess of the next step, and should allow the model to move forward in time. Good luck!
@Paul J - Thanks for the rant. You are right… the second type of algebraic loop are the ones that cause me the most frustration too. In some cases I find conflicting specifications are to blame. If a subsystem is marked as Atomic, Simulink must be able to compute all of the outputs at the same time. If there are dependencies on inputs, and those have a direct feed-through path back to the outputs, there is a sorting problem to be handled. Thanks for contributing to the discussion!
Hi Seth!
I’m very confused. in the Simulink document
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/f7-8243.html#f7-19688
solving simple algebraic loops with The Algebraic Constraint block and find z1 = 0, z2 = 1.
i solve this example without this block and find z1 = -1, z2 = 1;
Which answer is correct?
unfortunately mathworks can not be accessed in iran. I dont know why mathworks guys do that but I can’t solve my simulink related problems.
hi javad
if you have any problem please write me with my Email.
I hope that i can help you with your mat/simu problem.
Hi Suth,
I try to simulate a load tap-changing transformer in simulink but its control part has to be impelented in stateflow, I did it but simulating the system I get this error message,
Trouble solving algebraic loop containing ‘handy_ltc23/Three-Phase OLTC Regulating Transformer/Chart’ at time 5.033333333333321. Stopping simulation. There may be a singularity in the solution. If the model is correct, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)
The point is that I have to use stateflow for its control part and I can’t refuse that, inside the stateflow chart I just want to update a variable one unit every 4 sec, can Not I do it?
I’ll be very grateful if you give me a key
regards
Mohamamd