---
url: /dyad/stable/stdlib/BlockComponents/tests/Math.Tests.Division.md
description: >-
  Dyad Math.Tests.Division docs.  Division operation that divides a first input
  by a second input.
---

# `Math.Tests.Division` {#Math.Tests.Division}

Division operation that divides a first input by a second input.

Performs a simple division operation where the output y = u1/u2, dividing the first input (`u1`) by the second input (`u2`). This component requires that the second input (denominator) is non-zero to avoid division by zero errors. A second division block is driven by a sine numerator (sweeping negative and positive values) and a sine denominator kept strictly positive (3.5..6.5).

## Usage {#Usage}

`BlockComponents.Math.Tests.Division()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, division\_{+}u1 \right) \\
0 &= \mathrm{connect}\left( c2\_{+}y, division\_{+}u2 \right) \\
0 &= \mathrm{connect}\left( num\_{sine\_{+}y}, division\_{2\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( den\_{sine\_{+}y}, division\_{2\_{+}u2} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{c2.y}\left( t \right) &= \mathtt{c2.k} \\
\mathtt{division.y}\left( t \right) &= \frac{\mathtt{division.u1}\left( t \right)}{\mathtt{division.u2}\left( t \right)} \\
\mathtt{num_sine.y}\left( t \right) &= ifelse\left( \mathtt{num_sine.continuous}, ifelse\left( t \geq \mathtt{num_sine.start_time}, \sin\left( \mathtt{num_sine.phase} + 6.2832 ~ \mathtt{num_sine.frequency} ~ \left(  - \mathtt{num_sine.shift_time} + t \right) \right), \sin\left( \mathtt{num_sine.phase} + 6.2832 ~ \mathtt{num_sine.frequency} ~ \left(  - \mathtt{num_sine.shift_time} + \mathtt{num_sine.start_time} \right) \right) \right) ~ \mathtt{num_sine.amplitude}, ifelse\left( t \geq \mathtt{num_sine.start_time}, \mathtt{num_sine.amplitude} ~ \sin\left( \mathtt{num_sine.phase} + 6.2832 ~ \mathtt{num_sine.frequency} ~ \left(  - \mathtt{num_sine.shift_time} + t \right) \right), 0 \right) \right) + \mathtt{num_sine.offset} \\
\mathtt{den_sine.y}\left( t \right) &= \mathtt{den_sine.offset} + ifelse\left( \mathtt{den_sine.continuous}, \mathtt{den_sine.amplitude} ~ ifelse\left( t \geq \mathtt{den_sine.start_time}, \sin\left( \mathtt{den_sine.phase} + 6.2832 ~ \mathtt{den_sine.frequency} ~ \left(  - \mathtt{den_sine.shift_time} + t \right) \right), \sin\left( \mathtt{den_sine.phase} + 6.2832 ~ \mathtt{den_sine.frequency} ~ \left(  - \mathtt{den_sine.shift_time} + \mathtt{den_sine.start_time} \right) \right) \right), ifelse\left( t \geq \mathtt{den_sine.start_time}, \mathtt{den_sine.amplitude} ~ \sin\left( \mathtt{den_sine.phase} + 6.2832 ~ \mathtt{den_sine.frequency} ~ \left(  - \mathtt{den_sine.shift_time} + t \right) \right), 0 \right) \right) \\
\mathtt{division_2.y}\left( t \right) &= \frac{\mathtt{division_2.u1}\left( t \right)}{\mathtt{division_2.u2}\left( t \right)}
\end{align}
$$

## Source {#Source}

```dyad
"""
Division operation that divides a first input by a second input.

Performs a simple division operation where the output y = u1/u2, dividing the first input (`u1`)
by the second input (`u2`). This component requires that the second input (denominator) is non-zero
to avoid division by zero errors. A second division block is driven by a sine numerator (sweeping
negative and positive values) and a sine denominator kept strictly positive (3.5..6.5).
"""
test component Division
  "Constant block that outputs the value 3 (numerator)"
  c1 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 80, "x2": 130, "y2": 180, "rot": 0}
      }
    }
  }
  "Constant block that outputs the value 2 (denominator)"
  c2 = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 270, "x2": 130, "y2": 370, "rot": 0}
      }
    }
  }
  "Division block that divides the first input (u1) by the second input (u2)"
  division = BlockComponents.Math.Division() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 170, "x2": 430, "y2": 270, "rot": 0}
      }
    }
  }
  "Sine numerator sweeping negative and positive values"
  num_sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 470, "x2": 130, "y2": 570, "rot": 0}
      }
    }
  }
  "Sine denominator kept strictly positive to avoid division by zero"
  den_sine = BlockComponents.Sources.Sine(amplitude = 1.5, frequency = 1, offset = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 660, "x2": 130, "y2": 760, "rot": 0}
      }
    }
  }
  "Second division block driven by the sine sources"
  division_2 = BlockComponents.Math.Division() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 560, "x2": 430, "y2": 660, "rot": 0}
      }
    }
  }
relations
  "Connects the output of constant block c1 (3) to the numerator input of the division block"
  connect(division.u1, c1.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 190, "y": 190}, {"x": 190, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Connects the output of constant block c2 (2) to the denominator input of the division block"
  connect(division.u2, c2.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 190, "y": 250}, {"x": 190, "y": 320}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(division_2.u1, num_sine.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 580}, {"x": 285, "y": 520}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(division_2.u2, den_sine.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 640}, {"x": 285, "y": 710}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {"signals": ["division.y", "division_2.y", "num_sine.y", "den_sine.y"]}
      }
    }
  }
}
end
```

```dyad
"""
Division operation that divides a first input by a second input.

Performs a simple division operation where the output y = u1/u2, dividing the first input (`u1`)
by the second input (`u2`). This component requires that the second input (denominator) is non-zero
to avoid division by zero errors. A second division block is driven by a sine numerator (sweeping
negative and positive values) and a sine denominator kept strictly positive (3.5..6.5).
"""
test component Division
  "Constant block that outputs the value 3 (numerator)"
  c1 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 80, "x2": 130, "y2": 180, "rot": 0}
      }
    }
  }
  "Constant block that outputs the value 2 (denominator)"
  c2 = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 270, "x2": 130, "y2": 370, "rot": 0}
      }
    }
  }
  "Division block that divides the first input (u1) by the second input (u2)"
  division = BlockComponents.Math.Division() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 170, "x2": 430, "y2": 270, "rot": 0}
      }
    }
  }
  "Sine numerator sweeping negative and positive values"
  num_sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 470, "x2": 130, "y2": 570, "rot": 0}
      }
    }
  }
  "Sine denominator kept strictly positive to avoid division by zero"
  den_sine = BlockComponents.Sources.Sine(amplitude = 1.5, frequency = 1, offset = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 660, "x2": 130, "y2": 760, "rot": 0}
      }
    }
  }
  "Second division block driven by the sine sources"
  division_2 = BlockComponents.Math.Division() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 560, "x2": 430, "y2": 660, "rot": 0}
      }
    }
  }
relations
  "Connects the output of constant block c1 (3) to the numerator input of the division block"
  connect(division.u1, c1.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 190, "y": 190}, {"x": 190, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Connects the output of constant block c2 (2) to the denominator input of the division block"
  connect(division.u2, c2.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 190, "y": 250}, {"x": 190, "y": 320}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(division_2.u1, num_sine.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 580}, {"x": 285, "y": 520}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(division_2.u2, den_sine.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 640}, {"x": 285, "y": 710}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {"signals": ["division.y", "division_2.y", "num_sine.y", "den_sine.y"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](ecqjtvv.svg)

```julia
plt
```

![](sqkakjx.svg)

```julia
plt
```

![](sreoghp.svg)

```julia
plt
```

![](lvysdsa.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

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

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

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

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