How do I avoid an Algeraic loop?

1 view (last 30 days)
GD on 15 Jul 2015
Answered: Sebastian Castro on 15 Jul 2015
I have a simulink model of a car, I need to control the speed of car using PID, so I feedback the car speed to the controller. But at this moment I get an algebraic loop error. I am using ode23t variable step solver.I am avoiding this algebraic loop using a delay in feedback. I also had this idea of using a integrator immediately followed by differentiator in feedback loop, so initially a value of zero can be fed through feedback loop and algebraic loop is avoided. Does this second method make any sense? Also any other suggestions to avoid this algebraic loop? Any help will be appreciated! thank you!

Accepted Answer

Sebastian Castro
Sebastian Castro on 15 Jul 2015
The algebraic loop comes from the "P" branch of the PID controller. This input of the Simscape network is directly dependent on one of its outputs -- hence an algebraic loop.
If you're modeling a control algorithm using PID, there's two primary fixes:
  1. As you said, a Unit Delay block is good if it's acceptable for you to model a sensor delay with a discrete sample time. This is typically okay if your PID controller is running in Discrete mode.
  2. You can use a Transfer Fcn block to create a low-pass filter (for example 1/(0.01s + 1) ). This will break your loop and still keep the signal in continuous time if that's what you need.
Note that the cut-off frequency of the low-pass filter approach should be chosen carefully so you don't filter any meaningful system dynamics out of the Simscape model. You want something large enough to avoid that, but not something too small because a higher frequency controller can slow down your simulation. The best thing is to try with and without the filter and see if the results match up.
- Sebastian

More Answers (0)


Find more on General Applications 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!

Translated by