MATLAB: Problem with Algebraic Loop

algebraic loopalgebraic variableclosed loopdiscontinouitymatlab codersimulinksimulink coder

Hello all,
I have problems with Algebraic Loop. In Simulink I have a control system scheme (closed loop) and some parameters of a control algorithm are calculating in every step dependent of a controller and process output.
If I have a implementation with level-2 S function, where I can program Initialize routine, it is everything fine and there is no Algebraic Loop and also Simulink scheme works fine.
But, I want this Simulink scheme to be compliant with Code Generation, so I tried the Matlab Function implementation, and regarding code, everything is OK. But Matlab Function doesn't have Initialize routine, so I have Algebraic Loop, which returns me error. If I put IC block (Initial Condition) on some intermediate signals, I still have Algebraic Loop, but the Simulink scheme works and returns correct results. But from the Code Generation point of view, I must not have any Algebraic Loop, but I'm not sure how to get rid of it. I tried with different initializations of signals, putting some SS LTI in between to be not Direct Through, but it doesn't help.
Did maybe someone have similar problems? Any idea how to solve that?
Also, when Matlab returns warning, there are some discontinouities and some algebraic variables – which of these is causing problems, discontinouity or algebraic variable?
Thank you for all answers, ideas, anything.
Best regards,

Best Answer

to again answer myself, the answer here is combination of integrator and derivative on the signals, which are not initialized.
Related Question