## Simulink and an Algebraic Loop

By Joel Benway, DISTek Integration, Inc.

Model-based design can shift many design tasks from the lab and field to a computer monitor, increasing the ease and speed of development; however, this shift can also present challenges that do not exist in the real world. Algebraic loops are an example of these challenges. In a mathematical model created in Mathworks Simulink®, an algebraic loop occurs when an input and output have a circular dependency, i.e., they are dependent on each other at the exact same time which introduces something of a “chicken or the egg” dilemma for Simulink to solve (see fig. 1).

** Figure 1: A simple algebraic loop**

Simulink detects these situations and can compute the correct result by using more computing cycles on the problem iteratively. The pictured example is simple enough for Simulink to resolve that y(t) = u(t) – y(t), but not all algebraic loops can be solved. Those that can be solved not only take an unacceptable amount of time, but also cause errors while generating code. It would be difficult to describe a loop like this in C code. This method is not a recommended way of modeling, and the algebraic loops should be removed.

One way to clean the algebraic loops out of a model is to drop a discrete delay (see fig. 2), like a unit delay, in the loop such that the feedback is decoupled from the output using the last value as the new value during computation, i.e., y(t)=u(t)-y(t-1). This process is an intuitive way to solve an algebraic loop and is usually the intent of the user.

** Figure 2: A unit delay removing an algebraic loop**

For a more complex model, say one with both global and local feedback that causes multiple algebraic loops, a single unit delay can get the job done if it is placed in the signal path where it will break up both loops at once. One issue with using a unit delay to solve an algebraic loop is that the time loop is no longer continuous, instead, it uses discrete time steps. This solution is not acceptable for all systems so a different approach may be more appropriate.

** **

** Figure 3: Using a rate transition as a unit delay to remove an algebraic loop**

The model shown above (see fig. 3) uses a unit delay block to act as a motor or actuator, decoupling the output of the control subsystem from the input of the plant model as with the unit delay to prevent an algebraic loop. A better option here is a transfer function block to model the actuator, which would keep the signal continuous for low latency (see fig. 4).

** Figure 4: Improved model using a transfer function to remove an algebraic loop**

The difference can be visualized by plotting these two actuator outputs on the same scope (see fig. 5). Both can remove the algebraic loop in this model but a transfer function creates a continuous output to the plant model. This change could be important for some systems. For example, a plant model may require that the derivative of an input is continuous. Every model is a simplification of the real world but the presence of an algebraic loop is a sign that a model requires additional dynamics. Each algebraic loop should be approached with a thoughtful solution tailored to preserve the correct fidelity of the model.

** Figure 5: Comparison of a continuous time signal loop and discrete time signal loop**

For more information, see our white paper titled: Modeling & Simulation in Embedded Systems for Off-Highway Vehicles.

Joel Benway

MBSD Engineer

6612 Chancellor Drive, Ste. 600

Cedar Falls, IA 50613

Tel: 319-859-3639

Joel.Benway@DISTek.com

#### Featured DISTek Expert

Name:Benjamin

TitleVP-Business Development

Technical Strengths:C, C++, CAN, SAE J1939, Matlab, Simulink, Digital Signal Processing

Past ExperienceAutonomous steering for agricultural equipment using GPS or feeler-sensors; electro-hydraulic steering controls for joystick-driven loaders; hydrostatic transmission controls.

DISTek Employee Since:2006

What I love about my job:I enjoy learning, and the experts with whom I work provide me ample opportunity to do so. I also enjoy solving problems of many kinds, and am often given the opportunity to delve into a mechanical or hydraulic problem outside my primary area of electrical expertise.

Click HERE to become a DISTek EXPERT!