Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions Modelica/Math/Special.mo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ package Special "Library of special mathematical functions"
y :=-y;
end if;

annotation (Documentation(info="<html>
annotation (derivative=erfDer,
Documentation(info="<html>
<h4>Syntax</h4>
<blockquote><pre>
Special.<strong>erf</strong>(u);
Expand Down Expand Up @@ -137,7 +138,8 @@ erf(0.5) // = 0.520499877813047
else
y := 0;
end if;
annotation (Documentation(info="<html>
annotation (derivative=erfcDer,
Documentation(info="<html>
<h4>Syntax</h4>
<blockquote><pre>
Special.<strong>erfc</strong>(u);
Expand Down Expand Up @@ -214,7 +216,8 @@ erfc(0.5) // = 0.4795001221869534
y :=Internal.erfInvUtil(u, 1 - u);
end if;

annotation (smoothOrder=1, Documentation(info="<html>
annotation (smoothOrder=1,
Documentation(info="<html>
<h4>Syntax</h4>
<blockquote><pre>
Special.<strong>erfInv</strong>(u);
Expand Down Expand Up @@ -304,7 +307,8 @@ erfInv(0.9999999999) // = 4.572824958544925
y :=Internal.erfInvUtil(1-u, u);
end if;

annotation (Documentation(info="<html>
annotation (
Documentation(info="<html>
<h4>Syntax</h4>
<blockquote><pre>
Special.<strong>erfInv</strong>(u);
Expand Down Expand Up @@ -372,6 +376,20 @@ erfInv(1.999999) // = -3.4589107372909473
</html>"));
end erfcInv;

function erfDer "Derivative of erf-function"
extends Modelica.Icons.Function;
input Real u "Input argument";
input Real der_u "Derivative of input";
output Real y= 2/sqrt(Modelica.Constants.pi)*exp(-u^2)*der_u "Derivative of erf(u)";
end erfDer;

function erfcDer "Derivative of erfc-function"
extends Modelica.Icons.Function;
input Real u "Input argument";
input Real der_u "Derivative of input";
output Real y=-2/sqrt(Modelica.Constants.pi)*exp(-u^2)*der_u "Derivative of erfc(u)";
end erfcDer;

function sinc "Unnormalized sinc function: sinc(u) = sin(u)/u"
extends Modelica.Icons.Function;
input Real u "Input argument";
Expand Down
23 changes: 23 additions & 0 deletions ModelicaTest/Math.mo
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,29 @@ extends Modelica.Icons.ExamplesPackage;
annotation (experiment(StopTime=5));
end TestInterpolateTimeVarying;

model TestErf "Test error function"
extends Modelica.Icons.Example;
import Modelica.Math.Special;
Real x=time;
Real y1=Special.erf(x);
Real dy1=der(y1) "der(erf)";
Real y1i "integral(dy1) == erf ?";
Real y2=Special.erfc(x) "erfc == 1 - erf ?";
Real dy2=der(y2) "der(erfc)";
Real y2i "integral(dy2) == erfc ?";
initial equation
y1i=Special.erf(x);
y2i=Special.erfc(x);
equation
der(y1i)=dy1;
der(y2i)=dy2;
annotation (experiment(
StartTime=-10,
StopTime=10,
Interval=0.0001,
Tolerance=1e-06));
end TestErf;

package Random
function randomNumbers
"Demonstrate the generation of uniform random numbers in the range 0..1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
time
y1
dy1
y1i
y2
dy2
y2i