Skip to content
Add.md

Add

Weighted adder that outputs the sum of two scalar inputs with configurable gains.

Combines two input signals by multiplying each by its respective gain parameter and adding the results. The output is calculated as

y=k1u1+k2u2

where k1 and k2 are configurable gain factors that determine the weight of each input in the sum.

This component extends from SI2SO

Usage

Add(k1=1.0, k2=1.0)

Parameters:

NameDescriptionUnitsDefault value
k1Gain multiplier for the first input (u1)1
k2Gain multiplier for the second input (u2)1

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)

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

Behavior

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

Source

dyad
# Weighted adder that outputs the sum of two scalar inputs with configurable gains.
#
# Combines two input signals by multiplying each by its respective gain parameter and adding the results. The output
# is calculated as
#
# ```math
# y = k1 \cdot u1 + k2 \cdot u2
# ```
# where k1 and k2 are configurable gain factors that determine the weight of each input in the sum.
component Add
  extends SI2SO()
  # Gain multiplier for the first input (u1)
  parameter k1::Real = 1.0
  # Gain multiplier for the second input (u2)
  parameter k2::Real = 1.0
relations
  # Output equation: weighted sum of inputs
  y = k1*u1+k2*u2
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Add.svg"}}}
end
Flattened Source
dyad
# Weighted adder that outputs the sum of two scalar inputs with configurable gains.
#
# Combines two input signals by multiplying each by its respective gain parameter and adding the results. The output
# is calculated as
#
# ```math
# y = k1 \cdot u1 + k2 \cdot u2
# ```
# where k1 and k2 are configurable gain factors that determine the weight of each input in the sum.
component Add
  # First real-valued input signal
  u1 = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 150, "x2": 50, "y2": 250}}}}]
  # Second real-valued input signal
  u2 = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 750, "x2": 50, "y2": 850}}}}]
  # Real-valued output signal
  y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 1050, "y2": 550}}}}]
  # Gain multiplier for the first input (u1)
  parameter k1::Real = 1.0
  # Gain multiplier for the second input (u2)
  parameter k2::Real = 1.0
relations
  # Output equation: weighted sum of inputs
  y = k1*u1+k2*u2
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Add.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