blob: d897b8f55e3098523ce402973a7ae3158779a4d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/**
* @brief Calculates the Hypergeometric Function 0F1(;b;z)
* @param b0 in 0F1(;b0;z)
* @param z in 0F1(;b0;z)
* @param n number of itertions (precision)
* @return Result
*/
static double fractionRekursion0f1(const double c, const double z, unsigned int n)
{
//declaration
double a = 0.0;
double b = 0.0;
double Ak = 0.0;
double Bk = 0.0;
double Ak_1 = 0.0;
double Bk_1 = 0.0;
double Ak_2 = 0.0;
double Bk_2 = 0.0;
for (unsigned int k = 0; k <= n; ++k)
{
if (k == 0)
{
a = 1.0; //a0
//recursion fomula for A0, B0
Ak = a;
Bk = 1.0;
}
else if (k == 1)
{
a = 1.0; //a1
b = z/c; //b1
//recursion fomula for A1, B1
Ak = a * Ak_1 + b * 1.0;
Bk = a * Bk_1;
}
else
{
a = 1 + (z / (k * ((k - 1) + c)));//ak
b = -(z / (k * ((k - 1) + c))); //bk
//recursion fomula for Ak, Bk
Ak = a * Ak_1 + b * Ak_2;
Bk = a * Bk_1 + b * Bk_2;
}
//save old values
Ak_2 = Ak_1;
Bk_2 = Bk_1;
Ak_1 = Ak;
Bk_1 = Bk;
}
//approximation fraction
return Ak/Bk;
}
|