Add or subtract inputs
Simulink / Math Operations
The Sum block performs addition or subtraction on its inputs. The Add, Subtract, Sum of Elements, and Sum blocks are identical blocks. This block can add or subtract scalar, vector, or matrix inputs. It can also collapse the elements of a signal and perform a summation.
You specify the operations of the block with the List of signs
parameter with plus (+
), minus (-
), and
spacer (|
).
The number of +
and -
characters equals
the number of inputs. For example, +-+
requires three inputs.
The block subtracts the second (middle) input from the first (top) input, and
then adds the third (bottom) input.
A spacer character creates extra space between ports on the block icon.
If performing only addition, you can use a numerical value equal to the number of inputs.
If only there is only one input port, a single +
or
-
adds or subtracts the elements over all dimensions or
in the specified dimension.
The Sum block first converts the input data type to its accumulator data type, then performs the specified operations. The block converts the result to its output data type using the specified rounding and overflow modes.
Output calculation for the Sum block depends on the number of block inputs and the sign of input ports:
If the Sum block has... | And... | The formula for output calculation is... | Where... |
---|---|---|---|
One input port |
The input port sign is + |
y = e[0] + e[1] + e[2] ... + e[m] |
|
The input port sign is – |
y = 0.0 – e[0] – e[1] – e[2] ... – e[m] | ||
Two or more input ports |
All input port signs are – |
y = 0.0 – u[0] – u[1] – u[2] ... – u[n] |
|
The kth input port is the first port where the sign is + |
y = u[k] – u[0] – u[1] – u[2] – u[k–1] (+/–) u[k+1] ... (+/–) u[n] |
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|