Algebraic Loop Caused by MATLAB Function Block. How to Resolve Without Time Delay?
7 views (last 30 days)
Show older comments
Hello, I have a block diagram of a closed loop control system that uses a MATLAB Function Block to describe a plant model. In this function block I use MEX functions to acquire data from another software, so that I can generate outputs for the function block. I also use memory blocks to create persistent variables that are inputs and outputs from the function block. Because I am using some of the outputs as feedback in the control loop, it creates algebraic loops. To resolve this I was using delay blocks and memory blocks with initial conditions, but this shifts the signal by one time step which is undesirable.
My sim is a fixed time step of 1 second.
I tried to use the IC block as suggested from another post and a Mathworks page, but this doesn't resolve the algebraic loop for some reason. If I simply ignore the algebraic loop warnings, I get the desired response, but I am unsure if this has negative impacts on my simulation, such as step computation time, incorrect output values, etc.
1 Comment
Paul
on 6 Jan 2023
Adding an IC block doesn't remove an algebraic loop. The IC block is intended to help the algebraic loop solver solve the algebraic loop.
Accepted Answer
Fangjun Jiang
on 6 Jan 2023
If you suspect your MATLAB Function block or your MEX function caused the algebraic loop, consider setting this "Direct Feedthrough" flag false and try again.
This should only be done when it's realy hard to analyze where is the algebraic loop. Wether there is a direct feedthrough thus causing algebraic loop is a fact. It is not something that can be resolved by setting a flag. Inserting a delay is the only solution.
"If I simply ignore the algebraic loop warnings, I get the desired response, but I am unsure if this has negative impacts on my simulation, such as step computation time, incorrect output values, etc."
There shouldn't be any significant negative impacts. In fact, I think somewhere in the diagnostics you can set to not report this algebraic loop warning.
Simulink will automatically insert delays behind the scene to resolve the algebraic loop. If you get the desired response, then take it. You got different results when you add delays or memory blocks by yourself. It only means you added more delays or the delays are not added at the right place.
7 Comments
Fangjun Jiang
on 6 Jan 2023
@Paul, thanks for the comment. I definitely experienced the cases myself where delay bocks were added automatically by Simulink to resolve the algebraic loops.
I read the doc page again and it furthered my understanding of algebraic loops. Thanks!
I think there is a difference between us regarding the intepretation of "solve the algebraic loop".
In the "Sum block" example you mentioned, there is a loop, and there is a theoritically correct solution (Xa(t)=u(t)/2) for it. Simulink is able to find the solution through iteration. That is amazing. I never realized it. Notablly, it emphasizes that "The solver performs iterations to determine the solution to the algebraic constraint, if there is one."
When I mentioned it here, or what the OP is asking for here regarding "solve/resolve the algebraic loop" problem, is to "break the loop" or "remove the loop". For that, we are tying to set the flags, add the delays in the right place, etc. It is close to the first example described on this page.
Paul
on 6 Jan 2023
I wasn't trying to answer the OP's question, just commenting on other comments in the thread.
In summary, I think we are now in agreement on almost everything.
Simulink models can contain two types of algebraic loops: true and artificial.
Either type of algebaic loop can be removed. The speciific options for the user for doing so depend on the type of algebraic loop and the blocks contained in the loop.
If not removed, Simulink tries to solve either type of algebraic loop during execution using an iterative solver.
I think our only area of disagreement is if there are any circumstances under which Simulink will automatically add delay (or memory?) blocks to remove an algebraic loop. I've searched the 2021b doc and can't find anything about that. If you come across that in the future and remember this thread, I hope you'll come back here and provide more details, example, etc.
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!