Main Content

Algebraic Constraint

R2026b

Constrain signal value when solving algebraic loop

  • Algebraic Constraint block

Libraries:
Simulink / Math Operations

Description

The Algebraic Constraint block constrains the value of the input when solving an algebraic loop that contains the block. You can configure the block to apply either of these constraint equations:

f(z) = 0,

f(z) = z,

where:

  • z is an algebraic variable or vector of algebraic variables in the loop.

  • f(z) is the block input signal.

The block determines the value of the algebraic variable z that satisfies the specified constraint equation and provides the value as an output.

Solve Algebraic Loops as Differential-Algebraic Equations (DAEs)

Solving an algebraic loop as a DAE can significantly speed up simulations in some cases for models that:

  • Have continuous states

  • Use Algebraic Constraint blocks to constrain the value of coupled states between State-Space or Descriptor State-Space blocks

By default, the software solves algebraic loops as a system of equations expressed in the semi-explicit form:

x˙=f(x,z,t)0=g(x,z,t),

To solve the algebraic equations, the software invokes the algebraic loop solver.

To solve an algebraic loop as a DAE instead, set the Equation format parameter of each Algebraic Constraint block in the loop to Differential Algebraic Equation. The software solves the loop as a system of DAEs in the form:

Mx˙=Ax+Buy=Cx+Du,

where the algebraic variable z is treated as one of the continuous system states x.

To solve the loop, the software uses the solver specified to simulate the model. To solve algebraic loops as DAEs, you must simulate the model using an implicit solver.

Examples

expand all

Use the Algebraic Constraint block to solve the system

$$\begin{array}{c} z_1 + z_2 = 1\\ z_2 - z_1 = 1\end{array}$$

The model represents the problem in a vectorized form as

$$
 \left[\begin{array}{cc}
1 & 1\\
-1& 1
\end{array}\right]\left[\begin{array}{c}z_1\\z_2\end{array}\right]
=\left[\begin{array}{c}1\\1\end{array}\right]
$$

The signal fed to the Algebraic Constraint block $f(z)$ is a $2\times1$ vector of the form

$$\left[\begin{array}{c}z_1+z_2-1\\-z-1 +
z_2-1\end{array}\right] $$

The block is configured to constrain $f(z)$ to 0. Thus solving for $f(z) = 0$ yields the solution $z_1 = 0,\, z_2 = 1$

Extended Examples

Ports

Input

expand all

Connect the signal to constrain when solving for the algebraic variable z.

Data Types: double

Output

expand all

The output port provides the value of the algebraic variable z that satisfies the constraint equation.

Data Types: double

Parameters

expand all

Specify the constraint equation to solve as f(z) = 0 or f(z) = z.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Constraint
Values: "f(z) = 0" (default) | "f(z) = z"

Example: set_param("MyModel/Algebraic Constraint",Constraint="f(z) = z")

Specify the algorithm for the algebraic loop solver as one of these options:

  • auto — The software determines the algebraic loop solver algorithm to use.

  • Trust region [1], [2] — The algebraic loop solver uses the trust-region algorithm.

  • Line search [3] — The algebraic loop solver uses the line-search algorithm.

When you solve the loop as a DAE, this parameter specifies the algorithm used to compute consistent initial conditions.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Solver
Values: "auto" (default) | "Trust region" | "Line search"

Example: set_param("MyModel/Algebraic Constraint",Solver="Trust region")

Specify a tolerance that provides an appropriate balance of accuracy and performance. Smaller tolerance values can improve accuracy but can also slow down simulation. Larger tolerance values can allow for faster simulation but can also reduce accuracy.

Dependencies

To enable this parameter, set the Solver parameter to a value other than auto.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Tolerance
Values: "auto" (default) | positive scalar

Example: set_param("MyModel/Algebraic Constraint",Tolerance="1e-6")

The software uses the initial guess as the initial value of the algebraic variable when solving the algebraic loop. By default, the initial guess is 0. If the initial guess is close to the value that satisfies the constraint equations, in some cases, the software can solve the loop with fewer iterations.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: InitialGuess
Values: "0" (default) | scalar

Example: set_param("MyModel/Algebraic Constraint",InitialGuess="5")

Since R2026b

Specify how the software solves the algebraic loop that contains this block.

  • Algebraic Loop — The algebraic loop solver solves the loop as a system of equations expressed in the semi-explicit form. In linearization workflows, the software linearizes the loop to a nonsparse explicit state-space system.

  • Differential Algebraic Equation — The implicit solver for the model solves the loop as a system of DAEs. In linearization workflows, the software linearizes the loop to a sparse descriptor state-space system.

In some systems, solving algebraic loops as DAEs can significantly speed up simulations. To solve an algebraic loop as a system of DAEs:

  • You must simulate the model using an implicit solver.

  • The loop must contain one or more Algebraic Constraint blocks.

  • The Equation format parameter of all Algebraic Constraint blocks in a given loop must be Differential Algebraic Equation.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: EquationFormat
Values: "Algebraic Loop" (default) | "Differential Algebraic Equation"

Example: set_param("MyModel/Algebraic Constraint",EquationFormat="Differential Algebraic Equation")

Block Characteristics

Data Types

double

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

References

[1] Garbow, B. S., K. E. Hillstrom, and J. J. Moré. User Guide for MINPACK-1. Argonne, IL: Argonne National Laboratory, 1980.

[2] Rabinowitz, P. H. Numerical Methods for Nonlinear Algebraic Equations. New York: Gordon and Breach, 1970.

[3] Kelley, C. T. Iterative Methods for Linear and Nonlinear Equations. Society for Industrial and Applied Mathematics, Philadelphia, PA: 1995.

Extended Capabilities

expand all

Version History

Introduced before R2006a

expand all