Remove algebraic loop without delay

4 views (last 30 days)
Ale_798
Ale_798 on 18 Sep 2023
Commented: Paul on 19 Sep 2023
I have an algebraic loop in my Simulink scheme. Actually, it only generates a warning and the system runs perfectly fine anyway, because the solver is able to solve such a loop somehow.
The problem is that this causes a huge increment of the computational time for the simulation, that I cannot afford. Hence, I must remove the algebraic loop.
But the usual way of adding a delay in the scheme is not a solution, since it (correctly removes the loop, but) adds some dynamics to the system that does not make it work as it should.
How can I solve this problem?
  1 Comment
Paul
Paul on 19 Sep 2023
Hi Ale_798,
The first question to be answered is whether or not an algebraic loop is expected for the actual system you're trying to model. Sometimes, an algebraic loop is expected. But most of the time (in my own experience) an algebraic loop results from an improper or approximate represenation of the underlying system. Does the existence of the algebraic loop make sense for the system you're trying to model?

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 18 Sep 2023
Edited: John D'Errico on 18 Sep 2023
I don't know for sure how Simulink resolves the issue internally, but the answer seems straightforward. Consider the equation
x = 2*x + 3
You want to solve for x. Now the trivial solution is to perform algebra, since this is effectively an algebraic problem. And that equation is a trivial one to solve. But suppose it were slightly more complex?
x = tan(x) + 3
this is now a problem that has no algebraic solution. We can use a numerical solver to resolve it of course. BUT THAT ADDS TIME. How could it not?
The thing is, Simulink is not smart enough to resolve when a trivial algebraic operation could solve the problem. How could it? Simulink does not do symbolic algebra. And so, Simulink MUST resort always to a numerical solver. Yes, some of the time it will converge rapidly. But there is no assurance. And no matter what, it will be far less efficient than a simple, direct computation.
The trick of adding a delay sort of works, almost, because often it might be the case where x is slowly varying. Now it may cost us little to change the problem to something like
x(i+1) = f(x(i))
No algebraic loop anymore. But potentially different fundamental behavior.
I'd suggest the answer is to remove the implicit loop you have created. In the first case, you would have something as simple as:
x = -3
In the second case, as I said, there is no solution to that problem. At least, none besides the use of a solver, a root finder.
Sometimes difficult problems take time to solve. Then the solution often reduces to getting a faster computer.
  1 Comment
Ale_798
Ale_798 on 18 Sep 2023
Thanks for your answer. Then, it seems I have no alternatives but keeping the algebraic loop and waiting for the solver to do its work.
Since I cannot eliminate my problem, how could I at least minimize it? That is, what is the faster solver I can choose in the Model Settings? And are there other precautions I could take to this purpose?

Sign in to comment.

Categories

Find more on Manual Performance Optimization in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!