LIBRARY
Math.Tests.Tanh
Computes the hyperbolic tangent of constant and time-varying inputs.
Connects a constant source with value 0 to a Tanh block and verifies that tanh(0) = 0. A second Tanh block is driven by a sine wave (amplitude 3) that sweeps negative and positive values toward the saturation limits ±1.
Usage
BlockComponents.Math.Tests.Tanh()
Behavior
Source
dyad
"""
Computes the hyperbolic tangent of constant and time-varying inputs.
Connects a constant source with value 0 to a Tanh block and verifies that
tanh(0) = 0. A second Tanh block is driven by a sine wave (amplitude 3)
that sweeps negative and positive values toward the saturation limits ±1.
"""
test component Tanh
"Constant source providing the input value"
c1 = BlockComponents.Sources.Constant(k = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping negative and positive values"
sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"Tanh block under test"
tanh_block = BlockComponents.Math.Tanh() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Second Tanh block driven by the sine source"
tanh_block_2 = BlockComponents.Math.Tanh() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, tanh_block.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, tanh_block_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["tanh_block.y", "tanh_block_2.y", "sine.y"]}}
}
}
}
endFlattened Source
dyad
"""
Computes the hyperbolic tangent of constant and time-varying inputs.
Connects a constant source with value 0 to a Tanh block and verifies that
tanh(0) = 0. A second Tanh block is driven by a sine wave (amplitude 3)
that sweeps negative and positive values toward the saturation limits ±1.
"""
test component Tanh
"Constant source providing the input value"
c1 = BlockComponents.Sources.Constant(k = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping negative and positive values"
sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"Tanh block under test"
tanh_block = BlockComponents.Math.Tanh() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Second Tanh block driven by the sine source"
tanh_block_2 = BlockComponents.Math.Tanh() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, tanh_block.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, tanh_block_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["tanh_block.y", "tanh_block_2.y", "sine.y"]}}
}
}
}
endTest Cases
Test Case case1
julia
pltjulia
pltjulia
plt