Name | Description |
---|---|
polynomial | Polynomial function |
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 |
smoothMax | Once continuously differentiable approximation to the maximum function |
smoothMin | Once continuously differentiable approximation to the minimum function |
spliceFunction | |
Examples | Collection of models that illustrate model use and test models |
BaseClasses | Library with base classes for mathematical functions |
y = a1 + a2 * x + a3 * x^2 + ...
Type | Name | Default | Description |
---|---|---|---|
Real | a[:] | Coefficients | |
Real | x | Independent variable |
Type | Name | Description |
---|---|---|
Real | y | Result |
function polynomial "Polynomial function" annotation(derivative=BaseClasses.der_polynomial);input Real a[:] "Coefficients"; input Real x "Independent variable"; output Real y "Result"; protected parameter Integer n = size(a, 1)-1; Real xp[n+1] "Powers of x"; algorithm xp[1] :=1; for i in 1:n loop xp[i+1] :=xp[i]*x; end for; y :=a*xp; end polynomial;
y = a1 + a2 * x1 + a3 *x1^2 + (a4 + a5 * x1 + a6 *x1^2) * 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 |
function quadraticLinear "Function that is quadratic in first argument and linear in second argument" input Real a[6] "Coefficients"; input Real x1 "Independent variable for quadratic part"; input Real x2 "Independent variable for linear part"; output Real y "Result"; protected Real x1Sq; algorithm x1Sq :=x1*x1; y :=a[1] + a[2]*x1 + a[3]*x1Sq + (a[4] + a[5]*x1 + a[6]*x1Sq)*x2;end quadraticLinear;
Function that approximates y=|x|^n where n>0 so that
This function replaces y=|x|^n in the interval -delta...+delta by a 4-th order polynomial that has the same function value, first and second derivative at x=+/-delta.
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 -delta...+delta may be interpreted as the region where heat conduction dominates convection in the boundary layer.
See the package Examples 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 |
function regNonZeroPower "Power function, regularized near zero, but nonzero value for x=0" annotation(derivative=BaseClasses.der_regNonZeroPower);input Real x "Abscissa value"; input Real n "Exponent"; input Real delta = 0.01 "Abscissa value where transition occurs"; output Real y "Function value"; protected Real a1; Real a3; Real a5; Real delta2; Real x2; Real y_d "=y(delta)"; Real yP_d "=dy(delta)/dx"; Real yPP_d "=d^2y(delta)/dx^2"; algorithm if abs(x) > delta then y := abs(x)^n; else delta2 :=delta*delta; x2 :=x*x; y_d :=delta^n; yP_d :=n*delta^(n - 1); yPP_d :=n*(n - 1)*delta^(n - 2); a1 := -(yP_d/delta - yPP_d)/delta2/8; a3 := (yPP_d - 12 * a1 * delta2)/2; a5 := (y_d - delta2 * (a3 + delta2 * a1)); y := a5 + x2 * (a3 + x2 * a1); assert(a5>0, "delta is too small for this exponent n"); end if; end regNonZeroPower;
Function to provide a once continuously differentiable approximation to exp(- |x| ) in the interval |x| < delta for some positive delta
Type | Name | Default | Description |
---|---|---|---|
Real | x | Input argument | |
Real | delta | Transition point where approximation occurs |
Type | Name | Description |
---|---|---|
Real | y | Output argument |
function smoothExponential "Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta"input Real x "Input argument"; input Real delta "Transition point where approximation occurs"; output Real y "Output argument"; protected Real absX "Absolute value of x"; Real a2 "Coefficient for approximating function"; Real a3 "Coefficient for approximating function"; Real e; Real d2; Real x2; algorithm absX :=abs(x); if absX > delta then y := exp(-absX); else d2 := delta*delta; e := exp(-delta); a2 := (delta*e-4*(1-e))/2/d2; a3 := (e-1-a2*d2)/d2/d2; x2 := x*x; y := 1+x2*(a2+x2*a3); end if; end smoothExponential;
Once continuously differentiable approximation to the max(.,.) function.
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 smoothMax "Once continuously differentiable approximation to the maximum function"input Real x1 "First argument"; input Real x2 "Second argument"; input Real deltaX "Width of transition interval"; output Real y "Result"; algorithm y := Buildings.Utilities.Math.Functions.spliceFunction( pos=x1, neg=x2, x=x1-x2, deltax=deltaX); end smoothMax;
Once continuously differentiable approximation to the max(.,.) function.
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 smoothMin "Once continuously differentiable approximation to the minimum function"input Real x1 "First argument"; input Real x2 "Second argument"; input Real deltaX "Width of transition interval"; output Real y "Result"; algorithm y := Buildings.Utilities.Math.Functions.spliceFunction( pos=x1, neg=x2, x=x2-x1, deltax=deltaX); end smoothMin;
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 | 1 | Width of transition interval |
Type | Name | Description |
---|---|---|
Real | out | Smoothed value |
function spliceFunction annotation(derivative=BaseClasses.der_spliceFunction); input Real pos "Argument of x > 0"; input Real neg "Argument of x < 0"; input Real x "Independent value"; input Real deltax=1 "Width of transition interval"; output Real out "Smoothed value";protected Real scaledX; Real scaledX1; Real y; algorithm scaledX1 := x/deltax; scaledX := scaledX1*Modelica.Math.asin(1); if scaledX1 <= -0.999999999 then y := 0; elseif scaledX1 >= 0.999999999 then y := 1; else y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2; end if; out := pos*y + (1 - y)*neg; end spliceFunction;