Library with base classes for mathematical functions
Information
Extends from Modelica.Fluid.Icons.BaseClassLibrary (Icon for library).
Package Content
Power function, regularized near zero, but nonzero value for x=0
Inputs
| Type | Name | Default | Description |
| Real | x | | Abscissa value |
| Real | n | | Exponent |
| Real | delta | 0.01 | Abscissa value where transition occurs |
| Real | der_x | | |
| Real | der_2_x | | |
Outputs
| Type | Name | Description |
| Real | der_2_y | Function value |
Modelica definition
encapsulated function der_2_regNonZeroPower
"Power function, regularized near zero, but nonzero value for x=0"
input Real x "Abscissa value";
input Real n "Exponent";
input Real delta = 0.01 "Abscissa value where transition occurs";
input Real der_x;
input Real der_2_x;
output Real der_2_y "Function value";
protected
Real a1;
Real a3;
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
der_2_y := n*(n-1)*abs(x)^(n-2);
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;
der_2_y := 12*a1*x2+2*a3;
end if;
end der_2_regNonZeroPower;
Derivative for polynomial function
Information
This function computes the first derivative of a polynomial of arbitrary order.
The original polynomial has the form
y = a1 + a2 * x + a3 * x^2 + ...
This function computes new coefficients
b1 = a2, b2 = 2*a3, ...
and then calls recursively
Buildings.Utilities.Math.polynomial
Inputs
| Type | Name | Default | Description |
| Real | a[:] | | |
| Real | x | | |
| Real | dx | | |
Outputs
| Type | Name | Description |
| Real | y | |
Modelica definition
function der_polynomial "Derivative for polynomial function"
input Real a[:];
input Real x;
input Real dx;
output Real y;
protected
parameter Integer n = size(a, 1)-1;
Real b[n] "Coefficients of derivative polynomial";
algorithm
for i in 1:n loop
b[i] :=a[i+1]*i;
end for;
y := Buildings.Utilities.Math.Functions.polynomial(
a=b, x=x);
end der_polynomial;
Power function, regularized near zero, but nonzero value for x=0
Inputs
| Type | Name | Default | Description |
| Real | x | | Abscissa value |
| Real | n | | Exponent |
| Real | delta | 0.01 | Abscissa value where transition occurs |
| Real | der_x | | |
Outputs
| Type | Name | Description |
| Real | der_y | Function value |
Modelica definition
encapsulated function der_regNonZeroPower
"Power function, regularized near zero, but nonzero value for x=0"
annotation(derivative=BaseClasses.der_2_regNonZeroPower);
input Real x "Abscissa value";
input Real n "Exponent";
input Real delta = 0.01 "Abscissa value where transition occurs";
input Real der_x;
output Real der_y "Function value";
protected
Real a1;
Real a3;
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
der_y := sign(x)*n*abs(x)^(n-1);
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;
der_y := x * ( 4 * a1 * x * x + 2 * a3);
end if;
end der_regNonZeroPower;
Inputs
| Type | Name | Default | Description |
| Real | pos | | |
| Real | neg | | |
| Real | x | | |
| Real | deltax | 1 | |
| Real | dpos | | |
| Real | dneg | | |
| Real | dx | | |
| Real | ddeltax | 0 | |
Outputs
| Type | Name | Description |
| Real | out | |
Modelica definition
function der_spliceFunction
input Real pos;
input Real neg;
input Real x;
input Real deltax=1;
input Real dpos;
input Real dneg;
input Real dx;
input Real ddeltax=0;
output Real out;
protected
Real scaledX;
Real scaledX1;
Real dscaledX1;
Real y;
algorithm
scaledX1 := x/deltax;
scaledX := scaledX1*Modelica.Math.asin(1);
dscaledX1 := (dx - scaledX1*ddeltax)/deltax;
if scaledX1 <= -0.99999999999 then
y := 0;
elseif scaledX1 >= 0.9999999999 then
y := 1;
else
y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2;
end if;
out := dpos*y + (1 - y)*dneg;
if (abs(scaledX1) < 1) then
out := out + (pos - neg)*dscaledX1*Modelica.Math.asin(1)/2/(
Modelica.Math.cosh(Modelica.Math.tan(scaledX))*Modelica.Math.cos(
scaledX))^2;
end if;
end der_spliceFunction;
HTML-documentation generated by Dymola Mon Jun 14 14:29:05 2010.