Buildings.Utilities.Math.Functions

Package with mathematical functions

Package Content

NameDescription
Buildings.Utilities.Math.Functions.BaseClasses BaseClasses Library with base classes for mathematical functions
Buildings.Utilities.Math.Functions.Examples Examples Collection of models that illustrate model use and test models
Buildings.Utilities.Math.Functions.polynomial polynomial Polynomial function
Buildings.Utilities.Math.Functions.quadraticLinear quadraticLinear Function that is quadratic in first argument and linear in second argument
Buildings.Utilities.Math.Functions.regNonZeroPower regNonZeroPower Power function, regularized near zero, but nonzero value for x=0
Buildings.Utilities.Math.Functions.smoothExponential smoothExponential Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta
Buildings.Utilities.Math.Functions.smoothMax smoothMax Once continuously differentiable approximation to the maximum function
Buildings.Utilities.Math.Functions.smoothMin smoothMin Once continuously differentiable approximation to the minimum function
Buildings.Utilities.Math.Functions.spliceFunction spliceFunction  


Buildings.Utilities.Math.Functions.polynomial

Polynomial function

Information


This function computes a polynomial of arbitrary order.
The polynomial has the form
  y = a1 + a2 * x + a3 * x^2 + ...


Inputs

TypeNameDefaultDescription
Reala[:] Coefficients
Realx Independent variable

Outputs

TypeNameDescription
RealyResult

Modelica definition

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;

Buildings.Utilities.Math.Functions.quadraticLinear

Function that is quadratic in first argument and linear in second argument

Information


This function computes
  y =   a1 + a2 * x1 + a3 *x1^2 
     + (a4 + a5 * x1 + a6 *x1^2) * x2


Inputs

TypeNameDefaultDescription
Reala[6] Coefficients
Realx1 Independent variable for quadratic part
Realx2 Independent variable for linear part

Outputs

TypeNameDescription
RealyResult

Modelica definition

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;

Buildings.Utilities.Math.Functions.regNonZeroPower

Power function, regularized near zero, but nonzero value for x=0

Information


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.



Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realn Exponent
Realdelta0.01Abscissa value where transition occurs

Outputs

TypeNameDescription
RealyFunction value

Modelica definition

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;

Buildings.Utilities.Math.Functions.smoothExponential

Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta

Information


Function to provide a once continuously differentiable approximation to exp(- |x| ) in the interval |x| < delta for some positive delta



Inputs

TypeNameDefaultDescription
Realx Input argument
Realdelta Transition point where approximation occurs

Outputs

TypeNameDescription
RealyOutput argument

Modelica definition

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;

Buildings.Utilities.Math.Functions.smoothMax

Once continuously differentiable approximation to the maximum function

Information


Once continuously differentiable approximation to the max(.,.) function.



Inputs

TypeNameDefaultDescription
Realx1 First argument
Realx2 Second argument
RealdeltaX Width of transition interval

Outputs

TypeNameDescription
RealyResult

Modelica definition

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;

Buildings.Utilities.Math.Functions.smoothMin

Once continuously differentiable approximation to the minimum function

Information


Once continuously differentiable approximation to the max(.,.) function.



Inputs

TypeNameDefaultDescription
Realx1 First argument
Realx2 Second argument
RealdeltaX Width of transition interval

Outputs

TypeNameDescription
RealyResult

Modelica definition

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;

Buildings.Utilities.Math.Functions.spliceFunction

Information


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.



Inputs

TypeNameDefaultDescription
Realpos Argument of x > 0
Realneg Argument of x < 0
Realx Independent value
Realdeltax1Width of transition interval

Outputs

TypeNameDescription
RealoutSmoothed value

Modelica definition

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;

HTML-documentation generated by Dymola Tue Sep 29 08:10:29 2009.