Package with mathematical functions
This package contains functions for commonly used mathematical operations. The functions are used in the blocks Buildings.Utilities.Math.
Extends from Modelica.Icons.VariantsPackage (Icon for package containing variants).
Name | Description |
---|---|
average | Average of a vector |
bicubic | Bicubic function |
biquadratic | Biquadratic function |
booleanReplicator | Replicates Boolean signals |
cubicHermiteLinearExtrapolation | Interpolate using a cubic Hermite spline with linear extrapolation |
integerReplicator | Replicates integer signals |
inverseXRegularized | Function that approximates 1/x by a twice continuously differentiable function |
isMonotonic | Returns true if the argument is a monotonic sequence |
polynomial | Polynomial function |
powerLinearized | Power function that is linearized below a user-defined threshold |
quadraticLinear | Function that is quadratic in first argument and linear in second argument |
regNonZeroPower | Power function, regularized near zero, but nonzero value for x=0 |
smoothExponential | Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta |
smoothHeaviside | Once continuously differentiable approximation to the Heaviside function |
smoothLimit | Once continuously differentiable approximation to the limit function |
smoothMax | Once continuously differentiable approximation to the maximum function |
smoothMin | Once continuously differentiable approximation to the minimum function |
spliceFunction | |
splineDerivatives | Function to compute the derivatives for cubic hermite spline interpolation |
trapezoidalIntegration | Integration using the trapezoidal rule |
Examples | Collection of models that illustrate model use and test models |
BaseClasses | Package with base classes for Buildings.Utilities.Math.Functions |
Average of a vector
This block outputs the average of the vector.
Type | Name | Default | Description |
---|---|---|---|
Integer | nin | Number of inputs | |
Real | u[nin] | Input vector |
Type | Name | Description |
---|---|---|
Real | y | Result |
Bicubic function
y = a1 + a2 x1 + a3 x12 + a4 x2 + a5 x22 + a6 x1 x2 + a7 x1^3 + a8 x2^3 + a9 x12 x2 + a10 x1 x22
Type | Name | Default | Description |
---|---|---|---|
Real | a[10] | Coefficients | |
Real | x1 | Independent variable | |
Real | x2 | Independent variable |
Type | Name | Description |
---|---|---|
Real | y | Result |
Biquadratic function
y = a1 + a2 x1 + a3 x12 + a4 x2 + a5 x22 + a6 x1 x2
Type | Name | Default | Description |
---|---|---|---|
Real | a[6] | Coefficients | |
Real | x1 | Independent variable | |
Real | x2 | Independent variable |
Type | Name | Description |
---|---|---|
Real | y | Result |
Replicates Boolean signals
This function replicates the boolean input signal to an array of nout
identical output signals.
Type | Name | Default | Description |
---|---|---|---|
Integer | nout | 1 | Number of outouts |
Boolean | u | Boolean input signal |
Type | Name | Description |
---|---|---|
Boolean | y[nout] | Boolean output signals |
Interpolate using a cubic Hermite spline with linear extrapolation
For x1 < x < x2, this function interpolates using cubic hermite spline. For x outside this interval, the function linearly extrapolates.
For how to use this function, see Buildings.Utilities.Math.Functions.Examples.CubicHermite.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | x1 | Lower abscissa value | |
Real | x2 | Upper abscissa value | |
Real | y1 | Lower ordinate value | |
Real | y2 | Upper ordinate value | |
Real | y1d | Lower gradient | |
Real | y2d | Upper gradient |
Type | Name | Description |
---|---|---|
Real | y | Interpolated ordinate value |
Replicates integer signals
This function replicates the integer input signal to an array of
nout
identical output signals.
Type | Name | Default | Description |
---|---|---|---|
Integer | nout | Number of outputs | |
Integer | u | Integer input signal |
Type | Name | Description |
---|---|---|
Integer | y[nout] | Integer output signals |
Function that approximates 1/x by a twice continuously differentiable function
Function that approximates y=1 ⁄ x inside the interval -δ ≤ x ≤ δ. The approximation is twice continuously differentiable with a bounded derivative on the whole real line.
See the package Examples
for the graph.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | delta | Abscissa value below which approximation occurs |
Type | Name | Description |
---|---|---|
Real | y | Function value |
Returns true if the argument is a monotonic sequence
This function returns true
if its argument is
monotonic increasing or decreasing, and false
otherwise.
If strict=true
, then strict monotonicity is tested,
otherwise weak monotonicity is tested.
Type | Name | Default | Description |
---|---|---|---|
Real | x[:] | Sequence to be tested | |
Boolean | strict | false | Set to true to test for strict monotonicity |
Type | Name | Description |
---|---|---|
Boolean | monotonic | True if x is monotonic increasing or decreasing |
Polynomial function
y = a1 + a2 x + a3 x2 + ...
Type | Name | Default | Description |
---|---|---|---|
Real | x | Independent variable | |
Real | a[:] | Coefficients |
Type | Name | Description |
---|---|---|
Real | y | Result |
Power function that is linearized below a user-defined threshold
For x < x0, this function replaces y=xn by a linear function that is continuously differentiable everywhere.
A typical use of this function is to replace T = T4(1/4) in a radiation balance to ensure that the function is defined everywhere. This can help solving the initialization problem when a solver may be far from a solution and hence T4 < 0.
See the package Examples
for the graph.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | n | Exponent | |
Real | x0 | Abscissa value below which linearization occurs |
Type | Name | Description |
---|---|---|
Real | y | Function value |
Function that is quadratic in first argument and linear in second argument
y = a1 + a2 x1 + a3 x12 + (a4 + a5 x1 + a6 x12) x2
Type | Name | Default | Description |
---|---|---|---|
Real | a[6] | Coefficients | |
Real | x1 | Independent variable for quadratic part | |
Real | x2 | Independent variable for linear part |
Type | Name | Description |
---|---|---|
Real | y | Result |
Power function, regularized near zero, but nonzero value for x=0
This function replaces y=|x|n in the interval -δ...+δ by a 4-th order polynomial that has the same function value and the first and second derivative at x=± δ.
A typical use of this function is to replace the function for the convective heat transfer coefficient for forced or free convection that is of the form h=c |dT|n for some constant c and exponent 0 ≤ n ≤ 1. By using this function, the original function that has an infinite derivative near zero and that takes on zero at the origin is replaced by a function with a bounded derivative and a non-zero value at the origin. Physically, the region -δ...+δ may be interpreted as the region where heat conduction dominates convection in the boundary layer.
See the packageExamples
for the graph.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | n | Exponent | |
Real | delta | 0.01 | Abscissa value where transition occurs |
Type | Name | Description |
---|---|---|
Real | y | Function value |
Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta
Function to provide a once continuously differentiable approximation to exp(- |x| ) in the interval |x| < δ for some positive δ
Type | Name | Default | Description |
---|---|---|---|
Real | x | Input argument | |
Real | delta | Transition point where approximation occurs |
Type | Name | Description |
---|---|---|
Real | y | Output argument |
Once continuously differentiable approximation to the Heaviside function
Once Lipschitz continuously differentiable approximation to the
Heaviside(.,.)
function.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Argument | |
Real | delta | Parameter used for scaling |
Type | Name | Description |
---|---|---|
Real | y | Result |
Once continuously differentiable approximation to the limit function
Once continuously differentiable approximation to the limit(.,.)
function.
The output is bounded to be in [l, u].
Note that the limit need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Type | Name | Default | Description |
---|---|---|---|
Real | x | Variable | |
Real | l | Low limit | |
Real | u | Upper limit | |
Real | deltaX | Width of transition interval |
Type | Name | Description |
---|---|---|
Real | y | Result |
Once continuously differentiable approximation to the maximum function
Once continuously differentiable approximation to the max(.,.)
function.
Note that the maximum need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Type | Name | Default | Description |
---|---|---|---|
Real | x1 | First argument | |
Real | x2 | Second argument | |
Real | deltaX | Width of transition interval |
Type | Name | Description |
---|---|---|
Real | y | Result |
Once continuously differentiable approximation to the minimum function
Once continuously differentiable approximation to the min(.,.)
function.
Note that the minimum need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Type | Name | Default | Description |
---|---|---|---|
Real | x1 | First argument | |
Real | x2 | Second argument | |
Real | deltaX | Width of transition interval |
Type | Name | Description |
---|---|---|
Real | y | Result |
Function to provide a once continuously differentialbe transition between to arguments.
The function is adapted from Modelica.Media.Air.MoistAir.Utilities.spliceFunction and provided here for easier accessability to model developers.
Type | Name | Default | Description |
---|---|---|---|
Real | pos | Argument of x > 0 | |
Real | neg | Argument of x < 0 | |
Real | x | Independent value | |
Real | deltax | Half width of transition interval |
Type | Name | Description |
---|---|---|
Real | out | Smoothed value |
Function to compute the derivatives for cubic hermite spline interpolation
This function computes the derivatives at the support points xi
that can be used as input for evaluating a cubic hermite spline.
If ensureMonotonicity=true
, then the support points yi
need to be monotone increasing (or increasing), and the computed derivatives
di are such that the cubic hermite is monotone increasing (or decreasing).
The algorithm to ensure monotonicity is based on the method described in Fritsch and Carlson (1980) for
ρ = ρ2.
This function is typically used with Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation which is used to evaluate the cubic spline. Because in many applications, the shape of the spline depends on parameters, this function has been implemented in such a way that all derivatives can be computed at once and then stored for use during the time stepping, in which the above function may be called.
F.N. Fritsch and R.E. Carlson, Monotone piecewise cubic interpolation. SIAM J. Numer. Anal., 17 (1980), pp. 238?246.
Type | Name | Default | Description |
---|---|---|---|
Real | x[:] | Support point, strict monotone increasing | |
Real | y[size(x, 1)] | Function values at x | |
Boolean | ensureMonotonicity | isMonotonic(y, strict=false) | Set to true to ensure monotonicity of the cubic hermite |
Type | Name | Description |
---|---|---|
Real | d[size(x, 1)] | Derivative at the support points |
Integration using the trapezoidal rule
This function computes a definite integral using the trapezoidal rule.
Type | Name | Default | Description |
---|---|---|---|
Integer | N | Number of integrand points | |
Real | f[:] | Integrands | |
Real | deltaX | Width of interval for Trapezoidal integration |
Type | Name | Description |
---|---|---|
Real | result | Result |