Skip to content
Add3.md

Add3

Weighted summation block that adds three scalar inputs with configurable gains.

A component that computes a weighted sum of three real inputs, allowing different gain factors to be applied to each input before summation. The output is calculated using the formula:

y=k1u1+k2u2+k3u3

where k_1, k_2, and k_3 are user-configurable gain parameters.

Usage

Add3(k1=1.0, k2=1.0, k3=1.0)

Parameters:

NameDescriptionUnitsDefault value
k1Gain of u11
k2Gain of u21
k3Gain of u31

Connectors

  • u1 - This connector represents a real signal as an input to a component (RealInput)

  • u2 - This connector represents a real signal as an input to a component (RealInput)

  • u3 - This connector represents a real signal as an input to a component (RealInput)

  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior

y(t)=k1u1(t)+k2u2(t)+k3u3(t)

Source

dyad
# Weighted summation block that adds three scalar inputs with configurable gains.
#
# A component that computes a weighted sum of three real inputs, allowing different gain factors to be
# applied to each input before summation. The output is calculated using the formula:
#
# ```math
# y = k_1 \cdot u_1 + k_2 \cdot u_2 + k_3 \cdot u_3
# ```
#
# where `k_1`, `k_2`, and `k_3` are user-configurable gain parameters.
component Add3
  # First real input signal
  u1 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input1", "x1": -50, "y1": 150, "x2": 50, "y2": 250}}
    }
  }]
  # Second real input signal
  u2 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input2", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }]
  # Third real input signal
  u3 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input3", "x1": -50, "y1": 750, "x2": 50, "y2": 850}}
    }
  }]
  # Output signal representing the weighted sum of inputs
  y = RealOutput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "output", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Gain of `u1`
  parameter k1::Real = 1.0
  # Gain of `u2`
  parameter k2::Real = 1.0
  # Gain of `u3`
  parameter k3::Real = 1.0
relations
  y = k1*u1+k2*u2+k3*u3
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Add3.svg"}}}
end
Flattened Source
dyad
# Weighted summation block that adds three scalar inputs with configurable gains.
#
# A component that computes a weighted sum of three real inputs, allowing different gain factors to be
# applied to each input before summation. The output is calculated using the formula:
#
# ```math
# y = k_1 \cdot u_1 + k_2 \cdot u_2 + k_3 \cdot u_3
# ```
#
# where `k_1`, `k_2`, and `k_3` are user-configurable gain parameters.
component Add3
  # First real input signal
  u1 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input1", "x1": -50, "y1": 150, "x2": 50, "y2": 250}}
    }
  }]
  # Second real input signal
  u2 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input2", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }]
  # Third real input signal
  u3 = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input3", "x1": -50, "y1": 750, "x2": 50, "y2": 850}}
    }
  }]
  # Output signal representing the weighted sum of inputs
  y = RealOutput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "output", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Gain of `u1`
  parameter k1::Real = 1.0
  # Gain of `u2`
  parameter k2::Real = 1.0
  # Gain of `u3`
  parameter k3::Real = 1.0
relations
  y = k1*u1+k2*u2+k3*u3
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Add3.svg"}}}
end


Test Cases

This is setup code, that must be run before each test case.

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
  • Examples

  • Experiments

  • Analyses

  • Tests