Math Function
MathThe MathFunction block applies a selectable analytical or integer-rounding mathematical operation to the incoming scalar signal . Supported operations include exponential, logarithmic (natural and base-10), power, remainder, and rounding functions (nearest, floor, ceil). It is commonly used in physical plant modeling (e.g., chemical kinetics, thermodynamics, fluid drag, acoustic decibel scaling) and signal processing without requiring custom code blocks.
Mathematical Model
The block computes the output as a function of the input signal and the secondary parameter constant ():
The mathematical behavior for each selectable function is defined as follows:
- Exponential (
exp):
```latex
y(t) = \exp(u(t)) = e^{u(t)}
```
- Natural Logarithm (
log):
```latex
y(t) = \ln(u(t)), \quad u(t) > 0
```
For non-positive inputs (), the block returns to avoid unhandled NaN propagation.
- Common Logarithm (
log10):
```latex
y(t) = \log_{10}(u(t)), \quad u(t) > 0
```
Returns for .
- Power (
pow):
```latex
y(t) = (u(t))^c
```
Raises the input base to the exponent specified by constant (). Negative bases with non-integer exponents produce NaN.
- Remainder (
rem):
```latex
y(t) = u(t) \bmod c = u(t) - c \cdot \operatorname{trunc}\left(\frac{u(t)}{c}\right)
```
Computes the floating-point remainder with division-by-zero protection (returns if ).
- Round (
round):
```latex
y(t) = \operatorname{round}(u(t))
```
Rounds to the nearest integer value.
- Floor (
floor):
```latex
y(t) = \lfloor u(t) \rfloor
```
Rounds down to the largest integer less than or equal to .
- Ceiling (
ceil):
```latex
y(t) = \lceil u(t) \rceil
```
Rounds up to the smallest integer greater than or equal to .
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | in |
Input | number | Required |
| ← Out | out |
Output | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
function |
Function | select | exp |
|
constant |
Constant (n) | number | 2 |
Usage Examples
Example 1: Arrhenius Temperature-Dependent Reaction Kinetics
In chemical reactor simulation, the reaction rate coefficient varies exponentially with temperature according to the Arrhenius law . Feeding the dimensionless normalized activation term into a MathFunction block with function = "exp" and multiplying the output by pre-exponential factor models continuous kinetic reaction rates.
Example 2: Sound Pressure Level Decibel (dB SPL) Conversion
In acoustic instrumentation, root-mean-square pressure is converted to decibels relative to the hearing threshold (): . Dividing measured pressure by reference , feeding the ratio into MathFunction with function = "log10", and scaling by a Gain block of yields real-time calibrated decibel sound levels.
Remarks & Best Practices
- Logarithmic Out-of-Domain Protection: For non-positive inputs (),
logandlog10return rather than producing NaN. This allows downstream Saturation or MinMax blocks to clamp the signal safely without poisoning subsequent calculations. - Remainder Divisor Safeguard: When using
rem, if the divisor magnitude is smaller than , the block returns to prevent floating-point division by zero. - Fractional Exponents: Non-integer exponents in
pow(e.g. ) with negative bases produce NaN according to real arithmetic. For dedicated root extraction with configurable negative-input fallback modes, use the SquareRoot block. - Stateless WASM Execution: Executed directly as compiled WebAssembly arithmetic operations without internal state accumulators, requiring per evaluation.
Related Components
- SquareRoot: Specialized nth-root computation block with configurable negative-input fallback handling.
- Trigonometric: Trigonometric and hyperbolic functions (, , , etc.).
- Abs: Absolute value and sign extraction.
- Gain: Pure linear scaling by a constant factor.