−

Subtraction

Math
Run the live example Free · no sign-up · runs in your browser

The Subtraction block performs algebraic subtraction between two input signals: output = in1 − in2 (minuend minus subtrahend). Multiple connections to either port are automatically summed according to their respective signs.

In feedback control loops, the Subtraction block is the canonical comparison node where the measured plant output y(t)y(t) is subtracted from the command setpoint r(t)r(t) to generate the primary control error e(t)=r(t)−y(t)e(t) = r(t) - y(t). It provides an explicit, readable alternative to configuring a generic Sum block with negative signs.

Mathematical Model

y(t)=u1(t)−u2(t)y(t) = u_1(t) - u_2(t)

For multi-wire bus inputs connected to each terminal:

y(t)=∑i=1Mu1,i(t)−∑j=1Nu2,j(t)y(t) = \sum_{i=1}^{M} u_{1,i}(t) - \sum_{j=1}^{N} u_{2,j}(t)

Inputs & Outputs

Direction ID Label Type Status
→ In in1 + number Required
→ In in2 − number Required
← Out out Output number Output

Usage Examples

Example 1: Closed-Loop Feedback Error Calculation

In a position control loop, a Step block setpoint r(t)=10 radr(t) = 10\,\text{rad} connects to the positive port in1, and the measured output of an Integrator block y(t)y(t) connects to the negative port in2. The resulting error signal e(t)=10−y(t)e(t) = 10 - y(t) drives the input of a PIDController block, decreasing from 1010 to 00 as the plant tracks the setpoint.

Example 2: Differential Voltage and Common-Mode Rejection

In instrumentation circuits, sensing small signals across a bridge requires rejecting common-mode noise: v1(t)=Vcm(t)+12vdiff(t)v_1(t) = V_{\text{cm}}(t) + \frac{1}{2}v_{\text{diff}}(t) and v2(t)=Vcm(t)−12vdiff(t)v_2(t) = V_{\text{cm}}(t) - \frac{1}{2}v_{\text{diff}}(t). Connecting v1v_1 to in1 and v2v_2 to in2 eliminates Vcm(t)V_{\text{cm}}(t) completely, outputting the pure differential voltage vdiff(t)v_{\text{diff}}(t).

Remarks & Best Practices

  • Polarity Assignment: Port in1 (top left, labeled +) represents the positive term; port in2 (bottom left, labeled −) represents the negative term.
  • Feedback Loop Conventions: In block diagrams, negative feedback lines traditionally enter in2 from underneath or right-to-left, maintaining clean visual orientation.
  • Zero Latency: Executed as a direct SIMD scalar operation (in1 - in2) inside the Rust WASM evaluation step with zero numerical delay.
  • Multi-signal Summing: Supports multiple input wires on both ports with automatic algebraic reduction prior to subtraction.

Related Components

  • Sum: Multi-input addition with arbitrary sign configurations
  • Gain: Signal scaling and inversion (Gain = -1)
  • PIDController: Standard controller block accepting error signals
  • Saturation: Output limiting to model actuator force/torque boundaries