From d80e30b37d3b51fc4d47229fb3e88610fbc7a476 Mon Sep 17 00:00:00 2001 From: haddoucher Date: Mon, 22 Aug 2022 14:43:20 +0200 Subject: neuste Version --- buch/papers/0f1/listings/kettenbruchIterativ.c | 60 +++++++------------------ buch/papers/0f1/listings/kettenbruchRekursion.c | 60 ++++++++++++++++++------- 2 files changed, 60 insertions(+), 60 deletions(-) (limited to 'buch/papers/0f1/listings') diff --git a/buch/papers/0f1/listings/kettenbruchIterativ.c b/buch/papers/0f1/listings/kettenbruchIterativ.c index d897b8f..3caaf43 100644 --- a/buch/papers/0f1/listings/kettenbruchIterativ.c +++ b/buch/papers/0f1/listings/kettenbruchIterativ.c @@ -1,53 +1,27 @@ /** - * @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) + * @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) * @return Result */ -static double fractionRekursion0f1(const double c, const double z, unsigned int n) +static double fractionIter0f1(const double c, const double z, unsigned int k) { //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; + double abk = 0.0; + double temp = 0.0; - for (unsigned int k = 0; k <= n; ++k) + for (; k > 0; --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; + 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) } - //approximation fraction - return Ak/Bk; -} + + return a + temp; //a0 + temp +} \ No newline at end of file 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; +} -- cgit v1.2.1