ComparewConstant Icon
Compare.ComparewConstant
ComparewConstant()Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.
Variables
u: Real input signaly: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)threshold: Threshold value to compare againsttolerance: Acceptable deviation range around the threshold (default: 1e-5)
Description
This component extends the partialThresholdComparison component and adds a real-valued parameter (tolerance) to define an acceptable deviation range around the threshold.
Examples
threshold = 5.0, tolerance = 1e-5
u = 5.0 → y = 1.0 (exact match)
u = 5.000001 → y = 1.0 (within tolerance)
u = 4.99999 → y = 1.0 (within tolerance)
u = 5.1 → y = 0.0 (outside tolerance)
u = 4.8 → y = 0.0 (outside tolerance)This component extends from partialThresholdComparison
Usage
PrimitiveComponents.Compare.ComparewConstant(threshold, tolerance=1e-5)
Parameters:
| Name | Description | Units | Default value |
|---|---|---|---|
threshold | – | ||
tolerance | – | 0.00001 |
Connectors
y- This connector represents a real signal as an output from a component (RealOutput)u- This connector represents a real signal as an input to a component (RealInput)
Behavior
\[ \begin{align} y\left( t \right) &= ifelse\left( \left| - \mathtt{threshold} + u\left( t \right)\right| < \mathtt{tolerance}, 1, 0 \right) \end{align} \]
Source
"""
ComparewConstant()
Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.
# Variables
- `u`: Real input signal
- `y`: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)
- `threshold`: Threshold value to compare against
- `tolerance`: Acceptable deviation range around the threshold (default: 1e-5)
# Description
This component extends the `partialThresholdComparison` component and adds a real-valued
parameter (tolerance) to define an acceptable deviation range around the threshold.
# Examplesthreshold = 5.0, tolerance = 1e-5 u = 5.0 → y = 1.0 (exact match) u = 5.000001 → y = 1.0 (within tolerance) u = 4.99999 → y = 1.0 (within tolerance) u = 5.1 → y = 0.0 (outside tolerance) u = 4.8 → y = 0.0 (outside tolerance)
"""</span>
<span class="hljs-keyword">component</span> ComparewConstant
<span class="hljs-keyword">extends</span> <span class="hljs-link"><a href="../../types/partialThresholdComparison.html">partialThresholdComparison</a></span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">tolerance</span>::<span>Real</span> = 1e-5
<span class="hljs-keyword">relations</span>
y = ifelse((abs(u - threshold) < tolerance), float_sym(1.0), float_sym(0.0))
<span class="hljs-keyword">metadata</span> {
"Dyad": {
"labels": [
{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0},
{"label": " $(threshold)", "x": 500, "y": -150, "rot": 0}
],
"icons": {"default": "dyad://PrimitiveComponents/EqualThreshold.svg"}
}
}
<span class="hljs-keyword">end</span></code></pre>
Flattened Source
"""
ComparewConstant()
Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.
# Variables
- `u`: Real input signal
- `y`: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)
- `threshold`: Threshold value to compare against
- `tolerance`: Acceptable deviation range around the threshold (default: 1e-5)
# Description
This component extends the `partialThresholdComparison` component and adds a real-valued
parameter (tolerance) to define an acceptable deviation range around the threshold.
# Examplesthreshold = 5.0, tolerance = 1e-5 u = 5.0 → y = 1.0 (exact match) u = 5.000001 → y = 1.0 (within tolerance) u = 4.99999 → y = 1.0 (within tolerance) u = 5.1 → y = 0.0 (outside tolerance) u = 4.8 → y = 0.0 (outside tolerance)
"""</span>
<span class="hljs-keyword">component</span> ComparewConstant
# Real output(either 1.0 or 0.0)
<span class="hljs-symbol">y</span> = <span>Dyad.RealOutput</span>() {
"Dyad": {
"placement": {
"diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
"icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
}
}
}
# Real input
<span class="hljs-symbol">u</span> = <span>Dyad.RealInput</span>() {
"Dyad": {
"placement": {
"diagram": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
"icon": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
}
}
}
# threshold to compare against
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">threshold</span>::<span>Real</span>()
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">tolerance</span>::<span>Real</span> = 1e-5
<span class="hljs-keyword">relations</span>
y = ifelse((abs(u - threshold) < tolerance), float_sym(1.0), float_sym(0.0))
<span class="hljs-keyword">metadata</span> {
"Dyad": {
"labels": [
{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0},
{"label": " $(threshold)", "x": 500, "y": -150, "rot": 0}
],
"icons": {"default": "dyad://PrimitiveComponents/EqualThreshold.svg"}
}
}
<span class="hljs-keyword">end</span></code></pre>
Test Cases
No test cases defined.
Related
- Examples
- Experiments
- Analyses