forked from tsai/mathnet-numerics
Browse Source
Added incomplete Beta functions. Signed-off-by: jvangael <jurgen.vangael@gmail.com>la-knuth
10 changed files with 858 additions and 172 deletions
@ -0,0 +1,386 @@ |
|||||
|
// <copyright file="Gamma.cs" company="Math.NET">
|
||||
|
// Math.NET Numerics, part of the Math.NET Project
|
||||
|
// http://mathnet.opensourcedotnet.info
|
||||
|
//
|
||||
|
// Copyright (c) 2009 Math.NET
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person
|
||||
|
// obtaining a copy of this software and associated documentation
|
||||
|
// files (the "Software"), to deal in the Software without
|
||||
|
// restriction, including without limitation the rights to use,
|
||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the
|
||||
|
// Software is furnished to do so, subject to the following
|
||||
|
// conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be
|
||||
|
// included in all copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
// <contribution>
|
||||
|
// Cephes Math Library, Stephen L. Moshier
|
||||
|
// ALGLIB, Sergey Bochkanov
|
||||
|
// </contribution>
|
||||
|
|
||||
|
namespace MathNet.Numerics |
||||
|
{ |
||||
|
using System; |
||||
|
using Properties; |
||||
|
|
||||
|
public static partial class SpecialFunctions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The order of the <see cref="GammaLn"/> approximation.
|
||||
|
/// </summary>
|
||||
|
private const int Gamma_n = 10; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Auxiliary variable when evaluating the <see cref="GammaLn"/> function.
|
||||
|
/// </summary>
|
||||
|
private const double Gamma_r = 10.900511; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Polynomial coefficients for the <see cref="GammaLn"/> approximation.
|
||||
|
/// </summary>
|
||||
|
private static readonly double[] Gamma_dk = |
||||
|
new[] |
||||
|
{ |
||||
|
2.48574089138753565546e-5, |
||||
|
1.05142378581721974210, |
||||
|
-3.45687097222016235469, |
||||
|
4.51227709466894823700, |
||||
|
-2.98285225323576655721, |
||||
|
1.05639711577126713077, |
||||
|
-1.95428773191645869583e-1, |
||||
|
1.70970543404441224307e-2, |
||||
|
-5.71926117404305781283e-4, |
||||
|
4.63399473359905636708e-6, |
||||
|
-2.71994908488607703910e-9 |
||||
|
}; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the logarithm of the Gamma function.
|
||||
|
/// </summary>
|
||||
|
/// <param name="z">The argument of the gamma function.</param>
|
||||
|
/// <returns>The logarithm of the gamma function.</returns>
|
||||
|
/// <remarks>
|
||||
|
/// <para>This implementation of the computation of the gamma and logarithm of the gamma function follows the derivation in
|
||||
|
/// "An Analysis Of The Lanczos Gamma Approximation", Glendon Ralph Pugh, 2004.
|
||||
|
/// We use the implementation listed on p. 116 which achieves an accuracy of 16 floating point digits. Although 16 digit accuracy
|
||||
|
/// should be sufficient for double values, improving accuracy is possible (see p. 126 in Pugh).</para>
|
||||
|
/// <para>Our unit tests suggest that the accuracy of the Gamma function is correct up to 14 floating point digits.</para>
|
||||
|
/// </remarks>
|
||||
|
public static double GammaLn(double z) |
||||
|
{ |
||||
|
if (z < 0.5) |
||||
|
{ |
||||
|
double s = Gamma_dk[0]; |
||||
|
for (int i = 1; i <= Gamma_n; i++) |
||||
|
{ |
||||
|
s += Gamma_dk[i] / (i - z); |
||||
|
} |
||||
|
|
||||
|
return Constants.LnPi |
||||
|
- Math.Log(Math.Sin(Math.PI * z)) |
||||
|
- Math.Log(s) |
||||
|
- Constants.LogTwoSqrtEOverPi |
||||
|
- ((0.5 - z) * Math.Log((0.5 - z + Gamma_r) / Math.E)); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
double s = Gamma_dk[0]; |
||||
|
for (int i = 1; i <= Gamma_n; i++) |
||||
|
{ |
||||
|
s += Gamma_dk[i] / (z + i - 1.0); |
||||
|
} |
||||
|
|
||||
|
return Math.Log(s) |
||||
|
+ Constants.LogTwoSqrtEOverPi |
||||
|
+ ((z - 0.5) * Math.Log((z - 0.5 + Gamma_r) / Math.E)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the Gamma function.
|
||||
|
/// </summary>
|
||||
|
/// <param name="z">The argument of the gamma function.</param>
|
||||
|
/// <returns>The logarithm of the gamma function.</returns>
|
||||
|
/// <remarks>
|
||||
|
/// <para>
|
||||
|
/// This implementation of the computation of the gamma and logarithm of the gamma function follows the derivation in
|
||||
|
/// "An Analysis Of The Lanczos Gamma Approximation", Glendon Ralph Pugh, 2004.
|
||||
|
/// We use the implementation listed on p. 116 which should achieve an accuracy of 16 floating point digits. Although 16 digit accuracy
|
||||
|
/// should be sufficient for double values, improving accuracy is possible (see p. 126 in Pugh).
|
||||
|
/// </para>
|
||||
|
/// <para>Our unit tests suggest that the accuracy of the Gamma function is correct up to 13 floating point digits.</para>
|
||||
|
/// </remarks>
|
||||
|
public static double Gamma(double z) |
||||
|
{ |
||||
|
if (z < 0.5) |
||||
|
{ |
||||
|
double s = Gamma_dk[0]; |
||||
|
for (int i = 1; i <= Gamma_n; i++) |
||||
|
{ |
||||
|
s += Gamma_dk[i] / (i - z); |
||||
|
} |
||||
|
|
||||
|
return Math.PI / (Math.Sin(Math.PI * z) |
||||
|
* s |
||||
|
* Constants.TwoSqrtEOverPi |
||||
|
* Math.Pow((0.5 - z + Gamma_r) / Math.E, 0.5 - z)); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
double s = Gamma_dk[0]; |
||||
|
for (int i = 1; i <= Gamma_n; i++) |
||||
|
{ |
||||
|
s += Gamma_dk[i] / (z + i - 1.0); |
||||
|
} |
||||
|
|
||||
|
return s * Constants.TwoSqrtEOverPi * Math.Pow((z - 0.5 + Gamma_r) / Math.E, z - 0.5); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the upper incomplete regularized gamma function
|
||||
|
/// Q(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">The argument for the gamma function.</param>
|
||||
|
/// <param name="x">The lower integral limit.</param>
|
||||
|
/// <returns>The upper incomplete regularized gamma function.</returns>
|
||||
|
public static double GammaUpperRegularized(double a, double x) |
||||
|
{ |
||||
|
double result = 0; |
||||
|
double igammaepsilon = 0; |
||||
|
double igammabignumber = 0; |
||||
|
double igammabignumberinv = 0; |
||||
|
double ans = 0; |
||||
|
double ax = 0; |
||||
|
double c = 0; |
||||
|
double yc = 0; |
||||
|
double r = 0; |
||||
|
double t = 0; |
||||
|
double y = 0; |
||||
|
double z = 0; |
||||
|
double pk = 0; |
||||
|
double pkm1 = 0; |
||||
|
double pkm2 = 0; |
||||
|
double qk = 0; |
||||
|
double qkm1 = 0; |
||||
|
double qkm2 = 0; |
||||
|
|
||||
|
igammaepsilon = 0.000000000000001; |
||||
|
igammabignumber = 4503599627370496.0; |
||||
|
igammabignumberinv = 2.22044604925031308085 * 0.0000000000000001; |
||||
|
if (x <= 0 | a <= 0) |
||||
|
{ |
||||
|
result = 1; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
if (x < 1 | x < a) |
||||
|
{ |
||||
|
result = 1 - GammaLowerRegularized(a, x); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
ax = a * Math.Log(x) - x - GammaLn(a); |
||||
|
if (ax < -709.78271289338399) |
||||
|
{ |
||||
|
result = 0; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
ax = Math.Exp(ax); |
||||
|
y = 1 - a; |
||||
|
z = x + y + 1; |
||||
|
c = 0; |
||||
|
pkm2 = 1; |
||||
|
qkm2 = x; |
||||
|
pkm1 = x + 1; |
||||
|
qkm1 = z * x; |
||||
|
ans = pkm1 / qkm1; |
||||
|
do |
||||
|
{ |
||||
|
c = c + 1; |
||||
|
y = y + 1; |
||||
|
z = z + 2; |
||||
|
yc = y * c; |
||||
|
pk = pkm1 * z - pkm2 * yc; |
||||
|
qk = qkm1 * z - qkm2 * yc; |
||||
|
if (qk != 0) |
||||
|
{ |
||||
|
r = pk / qk; |
||||
|
t = Math.Abs((ans - r) / r); |
||||
|
ans = r; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
t = 1; |
||||
|
} |
||||
|
|
||||
|
pkm2 = pkm1; |
||||
|
pkm1 = pk; |
||||
|
qkm2 = qkm1; |
||||
|
qkm1 = qk; |
||||
|
|
||||
|
if (Math.Abs(pk) > igammabignumber) |
||||
|
{ |
||||
|
pkm2 = pkm2 * igammabignumberinv; |
||||
|
pkm1 = pkm1 * igammabignumberinv; |
||||
|
qkm2 = qkm2 * igammabignumberinv; |
||||
|
qkm1 = qkm1 * igammabignumberinv; |
||||
|
} |
||||
|
} |
||||
|
while (t > igammaepsilon); |
||||
|
|
||||
|
result = ans * ax; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the upper incomplete gamma function
|
||||
|
/// Gamma(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">The argument for the gamma function.</param>
|
||||
|
/// <param name="x">The lower integral limit.</param>
|
||||
|
/// <returns>The upper incomplete gamma function.</returns>
|
||||
|
public static double GammaUpperIncomplete(double a, double x) |
||||
|
{ |
||||
|
return GammaUpperRegularized(a, x) * Gamma(a); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the lower incomplete gamma function
|
||||
|
/// gamma(a,x) = int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">The argument for the gamma function.</param>
|
||||
|
/// <param name="x">The upper integral limit.</param>
|
||||
|
/// <returns>The lower incomplete gamma function.</returns>
|
||||
|
public static double GammaLowerIncomplete(double a, double x) |
||||
|
{ |
||||
|
return GammaLowerRegularized(a, x) * Gamma(a); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the lower incomplete regularized gamma function
|
||||
|
/// P(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">The argument for the gamma function.</param>
|
||||
|
/// <param name="x">The upper integral limit.</param>
|
||||
|
/// <returns>The lower incomplete gamma function.</returns>
|
||||
|
public static double GammaLowerRegularized(double a, double x) |
||||
|
{ |
||||
|
const double Epsilon = 0.000000000000001; |
||||
|
const double BigNumber = 4503599627370496.0; |
||||
|
const double BigNumberInverse = 2.22044604925031308085e-16; |
||||
|
|
||||
|
if (a < 0d || x < 0d) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException("a,x", Properties.Resources.ArgumentNotNegative); |
||||
|
} |
||||
|
|
||||
|
if (Precision.AlmostZero(a)) |
||||
|
{ |
||||
|
if (Precision.AlmostZero(x)) |
||||
|
{ |
||||
|
// either 0 or 1, depending on the limit direction
|
||||
|
return Double.NaN; |
||||
|
} |
||||
|
|
||||
|
return 1d; |
||||
|
} |
||||
|
|
||||
|
if (Precision.AlmostZero(x)) |
||||
|
{ |
||||
|
return 0d; |
||||
|
} |
||||
|
|
||||
|
double ax = (a * Math.Log(x)) - x - SpecialFunctions.GammaLn(a); |
||||
|
if (ax < -709.78271289338399) |
||||
|
{ |
||||
|
return 1d; |
||||
|
} |
||||
|
|
||||
|
if (x <= 1 || x <= a) |
||||
|
{ |
||||
|
double r2 = a; |
||||
|
double c2 = 1; |
||||
|
double ans2 = 1; |
||||
|
|
||||
|
do |
||||
|
{ |
||||
|
r2 = r2 + 1; |
||||
|
c2 = c2 * x / r2; |
||||
|
ans2 += c2; |
||||
|
} |
||||
|
while ((c2 / ans2) > Epsilon); |
||||
|
|
||||
|
return Math.Exp(ax) * ans2 / a; |
||||
|
} |
||||
|
|
||||
|
int c = 0; |
||||
|
double y = 1 - a; |
||||
|
double z = x + y + 1; |
||||
|
|
||||
|
double p3 = 1; |
||||
|
double q3 = x; |
||||
|
double p2 = x + 1; |
||||
|
double q2 = z * x; |
||||
|
double ans = p2 / q2; |
||||
|
|
||||
|
double error = 0; |
||||
|
|
||||
|
do |
||||
|
{ |
||||
|
c++; |
||||
|
y += 1; |
||||
|
z += 2; |
||||
|
double yc = y * c; |
||||
|
|
||||
|
double p = (p2 * z) - (p3 * yc); |
||||
|
double q = (q2 * z) - (q3 * yc); |
||||
|
|
||||
|
if (q != 0) |
||||
|
{ |
||||
|
double nextans = p / q; |
||||
|
error = Math.Abs((ans - nextans) / nextans); |
||||
|
ans = nextans; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
// zero div, skip
|
||||
|
error = 1; |
||||
|
} |
||||
|
|
||||
|
// shift
|
||||
|
p3 = p2; |
||||
|
p2 = p; |
||||
|
q3 = q2; |
||||
|
q2 = q; |
||||
|
|
||||
|
// normalize fraction when the numerator becomes large
|
||||
|
if (Math.Abs(p) > BigNumber) |
||||
|
{ |
||||
|
p3 *= BigNumberInverse; |
||||
|
p2 *= BigNumberInverse; |
||||
|
q3 *= BigNumberInverse; |
||||
|
q2 *= BigNumberInverse; |
||||
|
} |
||||
|
} |
||||
|
while (error > Epsilon); |
||||
|
|
||||
|
return 1d - (Math.Exp(ax) * ans); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,157 @@ |
|||||
|
// <copyright file="GammaTests.cs" company="Math.NET">
|
||||
|
// Math.NET Numerics, part of the Math.NET Project
|
||||
|
// http://mathnet.opensourcedotnet.info
|
||||
|
//
|
||||
|
// Copyright (c) 2009 Math.NET
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person
|
||||
|
// obtaining a copy of this software and associated documentation
|
||||
|
// files (the "Software"), to deal in the Software without
|
||||
|
// restriction, including without limitation the rights to use,
|
||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the
|
||||
|
// Software is furnished to do so, subject to the following
|
||||
|
// conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be
|
||||
|
// included in all copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace MathNet.Numerics.UnitTests.SpecialFunctionsTests |
||||
|
{ |
||||
|
using System; |
||||
|
using MbUnit.Framework; |
||||
|
using MathNet.Numerics; |
||||
|
|
||||
|
class GammaTests |
||||
|
{ |
||||
|
[Test] |
||||
|
[Row(Double.NaN, Double.NaN)] |
||||
|
[Row(0.1, 2.2527126517342059020062379568954763844479865649307379)] |
||||
|
[Row(1.0, 0.0)] |
||||
|
[Row(1.5, -0.12078223763524522234551844578164721225185272790259947)] |
||||
|
[Row(Constants.Pi / 2, -0.11590380084550241329912089415904874214542604767006895)] |
||||
|
[Row(2.0, 0.0)] |
||||
|
[Row(2.5, 0.28468287047291915963249466968270192432013769555989498)] |
||||
|
[Row(3.0, 0.693147180559945309417232121458176568075500134360255)] |
||||
|
[Row(Constants.Pi, 0.82769459232343710152957855845235995115350173412073715)] |
||||
|
[Row(3.5, 1.2009736023470742248160218814507129957702389154681574)] |
||||
|
[Row(4.0, 1.7917594692280550008124773583807022727229906921830034)] |
||||
|
[Row(4.5, 2.4537365708424422205041425034357161573318235106897606)] |
||||
|
[Row(5.0, 3.1780538303479456196469416012970554088739909609035161)] |
||||
|
[Row(5.5, 3.9578139676187162938774008558225909985513044919750065)] |
||||
|
[Row(10.1, 13.02752673863323715481371189614224148681183971709386)] |
||||
|
public void GammaLn(double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.GammaLn(x), 14); |
||||
|
} |
||||
|
|
||||
|
[Test] |
||||
|
[Row(Double.NaN, Double.NaN)] |
||||
|
[Row(-1.5, 2.3632718012073547030642233111215269103967326081631802)] |
||||
|
[Row(-0.5, -3.544907701811032054596334966682290365595098912244773)] |
||||
|
[Row(0.1, 9.5135076986687312858079798958252325009137161063903012)] |
||||
|
[Row(1.0, 1.0)] |
||||
|
[Row(1.5, 0.88622692545275801364908374167057259139877472806119326)] |
||||
|
[Row(Constants.Pi / 2, 0.89056089038153932801065963535912100593354196288475879)] |
||||
|
[Row(2.0, 1.0)] |
||||
|
[Row(2.5, 1.3293403881791370204736256125058588870981620920917912)] |
||||
|
[Row(3.0, 2.0)] |
||||
|
[Row(Constants.Pi, 2.2880377953400324179595889090602339228896881533562229)] |
||||
|
[Row(3.5, 3.3233509704478425511840640312646472177454052302294767)] |
||||
|
[Row(4.0, 6.0)] |
||||
|
[Row(4.5, 11.631728396567448929144224109426265262108918305803166)] |
||||
|
[Row(5.0, 24.0)] |
||||
|
[Row(5.5, 52.342777784553520181149008492418193679490132376114268)] |
||||
|
[Row(10.1, 454760.75144158558537612486797710217749925965322893332)] |
||||
|
public void Gamma(double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.Gamma(x), 13); |
||||
|
} |
||||
|
|
||||
|
[Test] |
||||
|
[Row(double.NaN, Double.NaN, Double.NaN)] |
||||
|
[Row(0.1, 1.0, 0.97587265627367222115949155252812057714751052498477013)] |
||||
|
[Row(0.1, 2.0, 0.99432617602018847196075251078067514034772764693462125)] |
||||
|
[Row(0.1, 8.0, 0.99999507519205198048686442150578226823401842046310854)] |
||||
|
[Row(1.5, 1.0, 0.42759329552912016600095238564127189392715996802703368)] |
||||
|
[Row(1.5, 2.0, 0.73853587005088937779717792402407879809718939080920993)] |
||||
|
[Row(1.5, 8.0, 0.99886601571021467734329986257903021041757398191304284)] |
||||
|
[Row(2.5, 1.0, 0.15085496391539036377410688601371365034788861473418704)] |
||||
|
[Row(2.5, 2.0, 0.45058404864721976739416885516693969548484517509263197)] |
||||
|
[Row(2.5, 8.0, 0.99315592607757956900093935107222761316136944145439676)] |
||||
|
[Row(5.5, 1.0, 0.0015041182825838038421585211353488839717739161316985392)] |
||||
|
[Row(5.5, 2.0, 0.030082976121226050615171484772387355162056796585883967)] |
||||
|
[Row(5.5, 8.0, 0.85886911973294184646060071855669224657735916933487681)] |
||||
|
public void GammaLowerRegularized(double a, double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.GammaLowerRegularized(a, x), 14); |
||||
|
} |
||||
|
|
||||
|
[Test] |
||||
|
[Row(double.NaN, Double.NaN, Double.NaN)] |
||||
|
[Row(0.1, 1.0, 9.2839720283798852469443229940217320532607158711056334)] |
||||
|
[Row(0.1, 2.0, 9.4595297305559030536119885480983751098528458886962883)] |
||||
|
[Row(0.1, 8.0, 9.5134608464704033372127589212547718314010339263844976)] |
||||
|
[Row(1.5, 1.0, 0.37894469164098470380394366597039213790868855578083847)] |
||||
|
[Row(1.5, 2.0, 0.65451037345177732033319477475056262302270310457635612)] |
||||
|
[Row(1.5, 8.0, 0.88522195804210983776635107858848816480298923071075222)] |
||||
|
[Row(2.5, 1.0, 0.20053759629003473411039172879412733941722170263949)] |
||||
|
[Row(2.5, 2.0, 0.59897957413602228465664030130712917348327070206302442)] |
||||
|
[Row(2.5, 8.0, 1.3202422842943799358198434659248530581833764879301293)] |
||||
|
[Row(5.5, 1.0, 0.078729729026968321691794205337720556329618007004848672)] |
||||
|
[Row(5.5, 2.0, 1.5746265342113649473739798668921124454837064926448459)] |
||||
|
[Row(5.5, 8.0, 44.955595480196465884619737757794960132425035578313584)] |
||||
|
public void GammaLowerIncomplete(double a, double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.GammaLowerIncomplete(a, x), 14); |
||||
|
} |
||||
|
|
||||
|
[Test] |
||||
|
[Row(double.NaN, Double.NaN, Double.NaN)] |
||||
|
[Row(0.100000, 1.000000, 0.024127343726327778840508447471879422852489475015229)] |
||||
|
[Row(0.100000, 2.000000, 0.0056738239798115280392474892193248596522723530653781)] |
||||
|
[Row(0.100000, 8.000000, 0.0000049248079480195131355784942177317659815795368919702)] |
||||
|
[Row(1.500000, 1.000000, 0.57240670447087983399904761435872810607284003197297)] |
||||
|
[Row(1.500000, 2.000000, 0.26146412994911062220282207597592120190281060919079)] |
||||
|
[Row(1.500000, 8.000000, 0.0011339842897853226567001374209697895824260180869567)] |
||||
|
[Row(2.500000, 1.000000, 0.84914503608460963622589311398628634965211138526581)] |
||||
|
[Row(2.500000, 2.000000, 0.54941595135278023260583114483306030451515482490737)] |
||||
|
[Row(2.500000, 8.000000, 0.0068440739224204309990606489277723868386305585456026)] |
||||
|
[Row(5.500000, 1.000000, 0.9984958817174161961578414788646511160282260838683)] |
||||
|
[Row(5.500000, 2.000000, 0.96991702387877394938482851522761264483794320341412)] |
||||
|
[Row(5.500000, 8.000000, 0.14113088026705815353939928144330775342264083066512)] |
||||
|
public void GammaUpperRegularized(double a, double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.GammaUpperRegularized(a, x), 14); |
||||
|
} |
||||
|
|
||||
|
[Test] |
||||
|
[Row(double.NaN, Double.NaN, Double.NaN)] |
||||
|
[Row(0.100000, 1.000000, 0.22953567028884603886365690180350044765300023528467)] |
||||
|
[Row(0.100000, 2.000000, 0.053977968112828232195991347726857391060870217694027)] |
||||
|
[Row(0.100000, 8.000000, 0.000046852198327948595220974570460669512682180005810156)] |
||||
|
[Row(1.500000, 1.000000, 0.50728223381177330984514007570018045349008617228036)] |
||||
|
[Row(1.500000, 2.000000, 0.23171655200098069331588896692000996837607162348484)] |
||||
|
[Row(1.500000, 8.000000, 0.0010049674106481758827326630820844265957854973504417)] |
||||
|
[Row(2.500000, 1.000000, 1.1288027918891022863632338837117315476809403894523)] |
||||
|
[Row(2.500000, 2.000000, 0.73036081404311473581698531119872971361489139002877)] |
||||
|
[Row(2.500000, 8.000000, 0.0090981038847570846537821465810058289147856041616617)] |
||||
|
[Row(5.500000, 1.000000, 52.264048055526551859457214287080473123160514369109)] |
||||
|
[Row(5.500000, 2.000000, 50.768151250342155233775028625526081234006425883469)] |
||||
|
[Row(5.500000, 8.000000, 7.3871823043570542965292707346232335470650967978006)] |
||||
|
public void GammaUpperIncomplete(double a, double x, double f) |
||||
|
{ |
||||
|
AssertHelpers.AlmostEqual(f, SpecialFunctions.GammaUpperIncomplete(a, x), 14); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue