Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simulink 'trouble solving algebraic loop' error -- need help

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Kate J.

Date: 13 Oct, 2011 19:47:29

Message: 1 of 7

I have a Simulink model that includes a biomechanical model block (takes muscle activation values as inputs & returns joint angles as outputs), as well as a controller block that calculates inputs to the biomechanical block (controller block inputs joint angles & other variables, and outputs muscle activation values). The outputs of the biomechanical block are fed back into the controller block as inputs. I have verified that these 2 blocks individually work without problems. However, when I try to run this model with both blocks and their feedback connections, I get the error message:

Trouble solving algebraic loop containing 'myModel/biomech_model' at time 0. 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)

I have already tried to reduce the step size, but this hasn't helped, and I continue to get the error message above. I also assigned names to all of the signals going into and coming out of both blocks, and have created a text file that assigns values to each of these variables; I run the text file before I try to run the Simulink model. However, I continue to get the error message above.

I'll note that I have a real-time block in this model; the error message above results, whether the real-time block is present or removed from the model.

Update: When I added Rate Transition blocks to the outputs of the biomechanical model block, the model actually ran for ~2 seconds; but then it stops, and gives the same error message as above (except that it cites "time 0.11"). So, the Rate Transition blocks resulted in a minor improvement, but the model still terminates in error.

Does anyone have suggestions about why my Simulink model that now contains these 2 blocks connected together in a feedback relationship, which blocks *individually* work with no problems, gives me the error message above when I run it? Thanks for your input.

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Phil Goddard

Date: 15 Oct, 2011 00:46:28

Message: 2 of 7

Have you looked in the section of the documentation that describes algebraic loops and how they are handled by Simulink?

The link is:
http://www.mathworks.com/help/toolbox/simulink/ug/f7-8243.html?#f7-19688

In summary, at every time step Simulink is solving an optimization problem that attempts to find signal values so that the input and output of the blocks in the algrebraic loop are consistent.
In your case it is having difficulty doing that and you need to try one of the suggestions in the documentation.

From your previous posts I think you use your model in a real-time system.
Note that Simulink Coder (formerly Real-time Workshop) will not work with models containing algebraic loops so you will need to get rid of the algrebraic loop -- simply making the step size smaller (even if it did work for the simulation) would not work for the real-time code.

Phil.

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Saurabh Mahapatra

Date: 15 Oct, 2011 17:04:12

Message: 3 of 7

Please put in a zero order delay to resolve this. An "algebraic" loop is the natural consequence of flow graph execution in time. An additional constraint is needed to remove the ambiguity "what should be computed first at a time step" much like the "chicken-egg" paradox. The unit delay will force one part of the loop to look back in time and use the previous value. Graphical representation and execution are not the same thing.

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Saurabh Mahapatra

Date: 15 Oct, 2011 17:14:10

Message: 4 of 7

I meant unit delay block.

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Kate J.

Date: 17 Oct, 2011 17:01:29

Message: 5 of 7

Thanks for your suggestions, Phil and Saurabh. A few updates and follow-up questions:

~ Phil, you're correct that I *had* been using xPC Target with this system; however, due to problems with my biomechanical model-block apparently not being able to run correctly with xPC Target (was generating all NAN values) in my Target Simulink model, I decided to try moving the biomechanical model block over to my Host Simulink model, and to completely eliminate my use of xPC Target & Real-Time Workshop.
     -- Instead, to achieve real-time functionality, I'm simply using a real-time block within my Host Simulink model. This shouldn't cause a problem, should it?

~ Saurabh, I added Unit Delay blocks into the signal-paths of the 4 outputs of my biomechanical model block, as well as the 6 outputs of my controller block (which are the inputs to my biomechanical model block). However, I still continue to get the same error message:
     "Derivative input 3 of 'Host_model/biomech_model' at time 0.135 is Inf or NaN. Stopping simulation. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)."

    -- what confuses me is that the biomech_model block takes 6 inputs, each of which is a regular *double* value; there are no derivative inputs to that model block. Could this be causing the problem?

~ I followed the advice within the Algebraic Loops documentation page, and ran the Simulink Debugger, & used the "ashow" command to display the algebraic loops; however, the message I get is, "No Algebraic loop found."
     -- Any explanations about why I'm receiving this "no algebraic loop found" message, if there *is* an apparent algebraic loop in my model?

Thanks.

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: David Lagarejo

Date: 21 Aug, 2013 19:42:09

Message: 6 of 7

"Kate J." wrote in message <j7hn19$qh7$1@newscl01ah.mathworks.com>...
> Thanks for your suggestions, Phil and Saurabh. A few updates and follow-up questions:
>
> ~ Phil, you're correct that I *had* been using xPC Target with this system; however, due to problems with my biomechanical model-block apparently not being able to run correctly with xPC Target (was generating all NAN values) in my Target Simulink model, I decided to try moving the biomechanical model block over to my Host Simulink model, and to completely eliminate my use of xPC Target & Real-Time Workshop.
> -- Instead, to achieve real-time functionality, I'm simply using a real-time block within my Host Simulink model. This shouldn't cause a problem, should it?
>
> ~ Saurabh, I added Unit Delay blocks into the signal-paths of the 4 outputs of my biomechanical model block, as well as the 6 outputs of my controller block (which are the inputs to my biomechanical model block). However, I still continue to get the same error message:
> "Derivative input 3 of 'Host_model/biomech_model' at time 0.135 is Inf or NaN. Stopping simulation. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)."
>
> -- what confuses me is that the biomech_model block takes 6 inputs, each of which is a regular *double* value; there are no derivative inputs to that model block. Could this be causing the problem?
>
> ~ I followed the advice within the Algebraic Loops documentation page, and ran the Simulink Debugger, & used the "ashow" command to display the algebraic loops; however, the message I get is, "No Algebraic loop found."
> -- Any explanations about why I'm receiving this "no algebraic loop found" message, if there *is* an apparent algebraic loop in my model?
>
> Thanks.


Hi, I use the Memory Block... this is solution... Ok Regards
 

Subject: Simulink 'trouble solving algebraic loop' error -- need help

From: Kate J.

Date: 26 Aug, 2013 16:30:12

Message: 7 of 7

> Hi, I use the Memory Block... this is solution... Ok Regards

Thanks for your suggestion, David. I'll look into implementing it if it becomes necessary for my project (which has now moved onto a different stage). Thanks!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us