Main Content

Break Algebraic Loops

This example shows how to create a MATLAB System block that can break an algebraic loop in the model.

System objects

System objects allow you to implement algorithms using MATLAB. System objects are a specialized kind of MATLAB object, designed specifically for implementing and simulating dynamic systems with inputs that change over time.

After you define a System object, you can include it in a Simulink model using a MATLAB System block.

Model Description

This example has a MATLAB System block that is used in a feedback loop in the model. The feedback loop is used to accumulate input values and the result is displayed in the Scope block. The feedback in the model creates an algebraic loop. To solve the algebraic loop, Simulink needs a block that has nondirect feedthrough. Blocks that have nondirect feedthrough are used in the feedback loops to break algebraic loops. This block can produce an output in the current time step without receiving the input first. In this example, MATLAB System block has nondirect feedthrough.

The MATLAB System block uses the System object UnitDelayNondirect that implements a unit delay. The output shows how the feedback loop accumulates the input signal values.

System Object Class Definition

You can access MATLAB source code used by the MATLAB System block by clicking the "Source Code" hyperlink from the block dialog. The UnitDelayNondirect System object implements the resetImpl, outputImpl, and updateImpl methods. The System object has one property called State.

  • resetImpl initializes the State property to 0.

  • outputImpl returns the value stored in State. This System object has nondirect feedthrough because outputImpl does not use any inputs.

  • updateImpl uses the inputs to update State.

classdef UnitDelayNondirect < matlab.System
% UnitDelayNondirect Delay input by one time step

properties(DiscreteState)
        State
    end

    methods(Access = protected)
        function resetImpl(obj)
            obj.State = 0; % Initialize states
        end
        function y = outputImpl(obj, ~)
            y = obj.State; % Output current state
            % Input is not used in this method
        end
        function updateImpl(obj,u)
            obj.State = u; % Update state with input
        end
    end
end

See Also

|

Related Topics