diff --git a/Modelica/Math/Special.mo b/Modelica/Math/Special.mo index 7988a2ef71..d2840efeb7 100644 --- a/Modelica/Math/Special.mo +++ b/Modelica/Math/Special.mo @@ -55,7 +55,8 @@ package Special "Library of special mathematical functions" y :=-y; end if; - annotation (Documentation(info=" + annotation (derivative=erfDer, + Documentation(info="
Special.erf(u);
@@ -137,7 +138,8 @@ erf(0.5) // = 0.520499877813047
else
y := 0;
end if;
- annotation (Documentation(info="
+ annotation (derivative=erfcDer,
+ Documentation(info="
Syntax
Special.erfc(u);
@@ -214,7 +216,8 @@ erfc(0.5) // = 0.4795001221869534
y :=Internal.erfInvUtil(u, 1 - u);
end if;
- annotation (smoothOrder=1, Documentation(info="
+ annotation (smoothOrder=1,
+ Documentation(info="
Syntax
Special.erfInv(u);
@@ -304,7 +307,8 @@ erfInv(0.9999999999) // = 4.572824958544925
y :=Internal.erfInvUtil(1-u, u);
end if;
- annotation (Documentation(info="
+ annotation (
+ Documentation(info="
Syntax
Special.erfInv(u);
@@ -372,6 +376,20 @@ erfInv(1.999999) // = -3.4589107372909473
"));
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";
diff --git a/ModelicaTest/Math.mo b/ModelicaTest/Math.mo
index 26d07b7cc9..7a08ac7da6 100644
--- a/ModelicaTest/Math.mo
+++ b/ModelicaTest/Math.mo
@@ -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"
diff --git a/ModelicaTest/Resources/Reference/ModelicaTest/Math/TestErf/comparisonSignals.txt b/ModelicaTest/Resources/Reference/ModelicaTest/Math/TestErf/comparisonSignals.txt
new file mode 100644
index 0000000000..940df8db01
--- /dev/null
+++ b/ModelicaTest/Resources/Reference/ModelicaTest/Math/TestErf/comparisonSignals.txt
@@ -0,0 +1,7 @@
+time
+y1
+dy1
+y1i
+y2
+dy2
+y2i