---
url: /dyad/stable/stdlib/BlockComponents/tests/Math.Tests.LinearDependency.md
description: >-
  Dyad Math.Tests.LinearDependency docs.  Computes a linear combination of
  constant and time-varying inputs.
---

# `Math.Tests.LinearDependency` {#Math.Tests.LinearDependency}

Computes a linear combination of constant and time-varying inputs.

Connects constant sources with values 2 and 3 to a LinearDependency block with y0=1, k1=2, k2=3, and verifies that y = 1 + 2_2 + 3_3 = 14. A second LinearDependency block with the same coefficients is driven by two sine waves that sweep negative and positive values.

## Usage {#Usage}

`BlockComponents.Math.Tests.LinearDependency()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, lin\_{block\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( c2\_{+}y, lin\_{block\_{+}u2} \right) \\
0 &= \mathrm{connect}\left( sine1\_{+}y, lin\_{block_2\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( sine2\_{+}y, lin\_{block_2\_{+}u2} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{c2.y}\left( t \right) &= \mathtt{c2.k} \\
\mathtt{lin_block.y}\left( t \right) &= \mathtt{lin_block.y0} + \mathtt{lin_block.k1} ~ \mathtt{lin_block.u1}\left( t \right) + \mathtt{lin_block.k2} ~ \mathtt{lin_block.u2}\left( t \right) \\
\mathtt{sine1.y}\left( t \right) &= ifelse\left( \mathtt{sine1.continuous}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right), \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + \mathtt{sine1.start_time} \right) \right) \right) ~ \mathtt{sine1.amplitude}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right) ~ \mathtt{sine1.amplitude}, 0 \right) \right) + \mathtt{sine1.offset} \\
\mathtt{sine2.y}\left( t \right) &= ifelse\left( \mathtt{sine2.continuous}, ifelse\left( t \geq \mathtt{sine2.start_time}, \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + t \right) \right), \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + \mathtt{sine2.start_time} \right) \right) \right) ~ \mathtt{sine2.amplitude}, ifelse\left( t \geq \mathtt{sine2.start_time}, \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + t \right) \right) ~ \mathtt{sine2.amplitude}, 0 \right) \right) + \mathtt{sine2.offset} \\
\mathtt{lin_block_2.y}\left( t \right) &= \mathtt{lin_block_2.y0} + \mathtt{lin_block_2.k1} ~ \mathtt{lin_block_2.u1}\left( t \right) + \mathtt{lin_block_2.k2} ~ \mathtt{lin_block_2.u2}\left( t \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Computes a linear combination of constant and time-varying inputs.

Connects constant sources with values 2 and 3 to a LinearDependency block
with y0=1, k1=2, k2=3, and verifies that y = 1 + 2*2 + 3*3 = 14. A second
LinearDependency block with the same coefficients is driven by two sine
waves that sweep negative and positive values.
"""
test component LinearDependency
  "Constant source providing the first input"
  c1 = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input"
  c2 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "LinearDependency block under test"
  lin_block = BlockComponents.Math.LinearDependency(y0 = 1, k1 = 2, k2 = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 50, "x2": 260, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the first input of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 20, "x2": 390, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the second input of the second block"
  sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 140, "x2": 390, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second LinearDependency block driven by the sine sources"
  lin_block_2 = BlockComponents.Math.LinearDependency(y0 = 1, k1 = 2, k2 = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 50, "x2": 540, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, lin_block.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, lin_block.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine1.y, lin_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine2.y, lin_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 190}, {"x": 410, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["lin_block.y", "lin_block_2.y", "sine1.y", "sine2.y"]}
      }
    }
  }
}
end
```

```dyad
"""
Computes a linear combination of constant and time-varying inputs.

Connects constant sources with values 2 and 3 to a LinearDependency block
with y0=1, k1=2, k2=3, and verifies that y = 1 + 2*2 + 3*3 = 14. A second
LinearDependency block with the same coefficients is driven by two sine
waves that sweep negative and positive values.
"""
test component LinearDependency
  "Constant source providing the first input"
  c1 = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input"
  c2 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "LinearDependency block under test"
  lin_block = BlockComponents.Math.LinearDependency(y0 = 1, k1 = 2, k2 = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 50, "x2": 260, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the first input of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 20, "x2": 390, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the second input of the second block"
  sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 140, "x2": 390, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second LinearDependency block driven by the sine sources"
  lin_block_2 = BlockComponents.Math.LinearDependency(y0 = 1, k1 = 2, k2 = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 50, "x2": 540, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, lin_block.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, lin_block.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine1.y, lin_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine2.y, lin_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 190}, {"x": 410, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["lin_block.y", "lin_block_2.y", "sine1.y", "sine2.y"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](lrxxvcc.svg)

```julia
plt
```

![](vocofnv.svg)

```julia
plt
```

![](uiitbfa.svg)

```julia
plt
```

![](xhbgqhv.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Math.Tests.LinearDependency.md)

  * [`LinearDependency`](Math.Tests.LinearDependency.md)

  * [`LinearDependency`](Math.Tests.LinearDependency.md)

  * [`Sine`](Math.Tests.LinearDependency.md)
