diff options
author | Erik Löffler <100943759+erik-loeffler@users.noreply.github.com> | 2022-08-16 16:23:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 16:23:52 +0200 |
commit | 20ab6151cde452d4fd604a074362c9ac945ea53d (patch) | |
tree | 7b834b3abf22791834ed40b9fe27d6457b12ea51 /buch/papers/0f1/listings/kettenbruchRekursion.c | |
parent | Merge pull request #6 from haddoucher/sturmliouville/erik-branch (diff) | |
parent | fix a typo (diff) | |
download | SeminarSpezielleFunktionen-20ab6151cde452d4fd604a074362c9ac945ea53d.tar.gz SeminarSpezielleFunktionen-20ab6151cde452d4fd604a074362c9ac945ea53d.zip |
Merge branch 'AndreasFMueller:master' into master
Diffstat (limited to '')
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchRekursion.c | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c index 3caaf43..d897b8f 100644 --- a/buch/papers/0f1/listings/kettenbruchRekursion.c +++ b/buch/papers/0f1/listings/kettenbruchRekursion.c @@ -1,27 +1,53 @@ /**
- * @brief Calculates the Hypergeometric Function 0F1(;c;z)
- * @param c in 0F1(;c;z)
- * @param z in 0F1(;c;z)
- * @param k number of itertions (precision)
+ * @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 fractionIter0f1(const double c, const double z, unsigned int k)
+static double fractionRekursion0f1(const double c, const double z, unsigned int n)
{
//declaration
double a = 0.0;
double b = 0.0;
- double abk = 0.0;
- double temp = 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 (; k > 0; --k)
+ for (unsigned int k = 0; k <= n; ++k)
{
- abk = z / (k * ((k - 1) + c)); //abk = ak, bk
-
- a = k > 1 ? (1 + abk) : 1; //a0, a1
- b = k > 1 ? -abk : abk; //b1
-
- temp = b / (a + temp); //bk / (ak + last result)
+ 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;
}
-
- return a + temp; //a0 + temp
-}
\ No newline at end of file + //approximation fraction
+ return Ak/Bk;
+}
|