Skip to content

Commit 306fb06

Browse files
authored
Merge pull request #977 from diluculo/mittagLeffler
Special Functions: add Mittag-Leffler function
2 parents 752c6f2 + ccff587 commit 306fb06

File tree

2 files changed

+590
-0
lines changed

2 files changed

+590
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// <copyright file="MittagLefflerTests.cs" company="Math.NET">
2+
// Math.NET Numerics, part of the Math.NET Project
3+
// https://numerics.mathdotnet.com
4+
// https://github.com/mathnet/mathnet-numerics
5+
//
6+
// Copyright (c) 2009-$CURRENT_YEAR$ Math.NET
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the "Software"), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
// </copyright>
29+
30+
using NUnit.Framework;
31+
32+
namespace MathNet.Numerics.Tests.SpecialFunctionsTests
33+
{
34+
using Complex = System.Numerics.Complex;
35+
36+
/// <summary>
37+
/// Marcum Q functions tests.
38+
/// </summary>
39+
[TestFixture, Category("Functions")]
40+
public class MittagLefflerTests
41+
{
42+
// E_0.5(z) = e^(z^2) erfc(-z)
43+
[TestCase(0.5, 2.0, 0.0, 108.9409043899779724123554, 0.0, 14)]
44+
[TestCase(0.5, -1.0, 1.0, 0.3047442052569125924571388, 0.2082189382028316272874373, 14)]
45+
// E_1(z) = e^z
46+
[TestCase(1.0, 0.0, 0.0, 1.0, 0.0, 14)]
47+
[TestCase(1.0, -1.0, 0.0, 0.3678794411714423215955238, 0.0, 13)]
48+
[TestCase(1.0, 1.0, 0.0, 2.718281828459045235360287, 0.0, 14)]
49+
[TestCase(1.0, 1.0, 1.0, 1.468693939915885157138968, 2.287355287178842391208172, 14)]
50+
[TestCase(1.0, 0.0, 1.0, 0.5403023058681397174009366, 0.8414709848078965066525023, 13)]
51+
[TestCase(1.0, 0.0, -1.0, 0.5403023058681397174009366, -0.8414709848078965066525023, 13)]
52+
[TestCase(1.0, 100.0, -100.0, 2.318014142308082065958914E43, 1.361170159893859825171534E43, 12)]
53+
// E_2(z) = cosh(sqrt(z))
54+
[TestCase(2.0, 1.0, 0.0, 1.543080634815243778477906, 0.0, 14)]
55+
[TestCase(2.0, -1.0, 0.0, 0.5403023058681397174009366, 0.0, 14)]
56+
// E_3(z) = 1/3 (e^(z^(1/3)) + 2 e^(-z^(1/3)/2) cos(1/2 sqrt(3) z^(1/3)))
57+
[TestCase(3.0, 1.0, 1.0, 1.1666611468490602090051780, 0.1694499559052291264367060, 14)]
58+
[TestCase(3.0, 100.0, -25.0, 33.06086298199622791072148, -13.33913169891245601081196, 14)]
59+
// E_4(z) = 1/2 (cos(z^(1/4)) + cosh(z^(1/4)))
60+
[TestCase(4.0, 1.0, -1.0, 1.0416666624911240883556243, -0.0417162740166212371993211, 12)]
61+
[TestCase(4.0, 10.0, -10.0, 1.416662489403313747387247, -0.421631159478217275004827, 14)]
62+
public void MittagLeffler(double alpha, double z1, double z2, double exp1, double exp2, int decimalPlaces)
63+
{
64+
AssertHelpers.AlmostEqualRelative(
65+
new Complex(exp1, exp2),
66+
SpecialFunctions.MittagLefflerE(alpha, new Complex(z1, z2)),
67+
decimalPlaces
68+
);
69+
}
70+
71+
[TestCase(0.5, 0.5, 0.5, 0.0, 1.5403698281390346, 0.0, 14)]
72+
[TestCase(1.5, 0.5, 0.5, 0.0, 1.1448466286155243, 0.0, 14)]
73+
[TestCase(2.3, 1.0, 0.7, 2.0, 1.201890136368392, 0.7895394560075035, 13)]
74+
public void GeneralizedMittagLeffler(double alpha, double beta, double z1, double z2, double exp1, double exp2, int decimalPlaces)
75+
{
76+
AssertHelpers.AlmostEqualRelative(
77+
new Complex(exp1, exp2),
78+
SpecialFunctions.MittagLefflerE(alpha, beta, new Complex(z1, z2)),
79+
decimalPlaces
80+
);
81+
}
82+
83+
[TestCase(0.75, 1.0, 1.2, -10, 1.0, 8.72265651199321222E-03, 1.30548998870915031E-03, 13)]
84+
public void ThreeParameterMittagLeffler(double alpha, double beta, double gamma, double z1, double z2, double exp1, double exp2, int decimalPlaces)
85+
{
86+
AssertHelpers.AlmostEqualRelative(
87+
new Complex(exp1, exp2),
88+
SpecialFunctions.MittagLefflerE(alpha, beta, gamma, new Complex(z1, z2)),
89+
decimalPlaces
90+
);
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)