From f3ced170faef47bcdf76f96eabf0534a58fd348e Mon Sep 17 00:00:00 2001 From: Fabian <@> Date: Fri, 22 Jul 2022 16:31:41 +0200 Subject: 0f1, struktur --- buch/papers/0f1/listings/kettenbruchIterativ.c | 45 +++++++++++++++++++++++++ buch/papers/0f1/listings/kettenbruchRekursion.c | 19 +++++++++++ buch/papers/0f1/listings/potenzreihe.c | 13 +++++++ 3 files changed, 77 insertions(+) create mode 100644 buch/papers/0f1/listings/kettenbruchIterativ.c create mode 100644 buch/papers/0f1/listings/kettenbruchRekursion.c create mode 100644 buch/papers/0f1/listings/potenzreihe.c (limited to 'buch/papers/0f1/listings') diff --git a/buch/papers/0f1/listings/kettenbruchIterativ.c b/buch/papers/0f1/listings/kettenbruchIterativ.c new file mode 100644 index 0000000..befea8e --- /dev/null +++ b/buch/papers/0f1/listings/kettenbruchIterativ.c @@ -0,0 +1,45 @@ +static double fractionRekursion0f1(const double c, const double x, unsigned int n) +{ + 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 = x/c; //b1 + //recursion fomula for A1, B1 + Ak = a * Ak_1 + b * 1.0; + Bk = a * Bk_1; + } + else + { + a = 1 + (x / (k * ((k - 1) + c)));//ak + b = -(x / (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; +} diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c new file mode 100644 index 0000000..958d4e1 --- /dev/null +++ b/buch/papers/0f1/listings/kettenbruchRekursion.c @@ -0,0 +1,19 @@ +static double fractionIter0f1(const double b0, const double z, unsigned int n) +{ + double a = 0.0; + double b = 0.0; + double abn = 0.0; + double temp = 0.0; + + for (; n > 0; --n) + { + abn = z / (n * ((n - 1) + b0)); //abn = ak, bk + + a = n > 1 ? (1 + abn) : 1; //a0, a1 + b = n > 1 ? -abn : abn; //b1 + + temp = b / (a + temp); + } + + return a + temp; //a0 + temp +} \ No newline at end of file diff --git a/buch/papers/0f1/listings/potenzreihe.c b/buch/papers/0f1/listings/potenzreihe.c new file mode 100644 index 0000000..bfaa0e3 --- /dev/null +++ b/buch/papers/0f1/listings/potenzreihe.c @@ -0,0 +1,13 @@ +#include + +static double powerseries(const double b, const double z, unsigned int n) +{ + double temp = 0.0; + + for (unsigned int k = 0; k < n; ++k) + { + temp += pow(z, k) / (factorial(k) * pochhammer(b, k)); + } + + return temp; +} \ No newline at end of file -- cgit v1.2.1 From c53e9fe25866376d1b3086579c01725444a04702 Mon Sep 17 00:00:00 2001 From: Fabian <@> Date: Tue, 26 Jul 2022 21:27:23 +0200 Subject: 0f1, Code ueberarbeitet --- buch/papers/0f1/listings/kettenbruchIterativ.c | 16 +++++-- buch/papers/0f1/listings/kettenbruchRekursion.c | 22 ++++++---- buch/papers/0f1/listings/potenzreihe.c | 56 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 11 deletions(-) (limited to 'buch/papers/0f1/listings') diff --git a/buch/papers/0f1/listings/kettenbruchIterativ.c b/buch/papers/0f1/listings/kettenbruchIterativ.c index befea8e..d897b8f 100644 --- a/buch/papers/0f1/listings/kettenbruchIterativ.c +++ b/buch/papers/0f1/listings/kettenbruchIterativ.c @@ -1,5 +1,13 @@ -static double fractionRekursion0f1(const double c, const double x, unsigned int n) +/** + * @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; @@ -21,15 +29,15 @@ static double fractionRekursion0f1(const double c, const double x, unsigned int else if (k == 1) { a = 1.0; //a1 - b = x/c; //b1 + b = z/c; //b1 //recursion fomula for A1, B1 Ak = a * Ak_1 + b * 1.0; Bk = a * Bk_1; } else { - a = 1 + (x / (k * ((k - 1) + c)));//ak - b = -(x / (k * ((k - 1) + c))); //bk + 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; diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c index 958d4e1..143683f 100644 --- a/buch/papers/0f1/listings/kettenbruchRekursion.c +++ b/buch/papers/0f1/listings/kettenbruchRekursion.c @@ -1,18 +1,26 @@ -static double fractionIter0f1(const double b0, const double z, unsigned int n) +/** + * @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 fractionIter0f1(const double c, const double z, unsigned int k) { + //declaration double a = 0.0; double b = 0.0; - double abn = 0.0; + double abk = 0.0; double temp = 0.0; - for (; n > 0; --n) + for (; k > 0; --k) { - abn = z / (n * ((n - 1) + b0)); //abn = ak, bk + abk = z / (k * ((k - 1) + c)); //abk = ak, bk - a = n > 1 ? (1 + abn) : 1; //a0, a1 - b = n > 1 ? -abn : abn; //b1 + a = k > 1 ? (1 + abk) : 1; //a0, a1 + b = k > 1 ? -abk : abk; //b1 - temp = b / (a + temp); + temp = b / (a + temp); ////bk / (ak + last result) } return a + temp; //a0 + temp diff --git a/buch/papers/0f1/listings/potenzreihe.c b/buch/papers/0f1/listings/potenzreihe.c index bfaa0e3..3eb9b86 100644 --- a/buch/papers/0f1/listings/potenzreihe.c +++ b/buch/papers/0f1/listings/potenzreihe.c @@ -1,5 +1,61 @@ #include +/** + * @brief Calculates pochhammer + * @param (a+n-1)! + * @return Result + */ +static double pochhammer(const double x, double n) +{ + double temp = x; + + if (n > 0) + { + while (n > 1) + { + temp *= (x + n - 1); + --n; + } + + return temp; + } + else + { + return 1; + } +} + +/** + * @brief Calculates the Factorial + * @param n! + * @return Result + */ +static double fac(int n) +{ + double temp = n; + + if (n > 0) + { + while (n > 1) + { + --n; + temp *= n; + } + return temp; + } + else + { + return 1; + } +} + +/** + * @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 powerseries(const double b, const double z, unsigned int n) { double temp = 0.0; -- cgit v1.2.1 From 220b382cf4b7019b199c3023ddab73ba2658e27a Mon Sep 17 00:00:00 2001 From: Fabian <@> Date: Wed, 27 Jul 2022 13:08:39 +0200 Subject: 0f1, bilder --- buch/papers/0f1/listings/kettenbruchRekursion.c | 8 ++++---- buch/papers/0f1/listings/potenzreihe.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'buch/papers/0f1/listings') diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c index 143683f..3caaf43 100644 --- a/buch/papers/0f1/listings/kettenbruchRekursion.c +++ b/buch/papers/0f1/listings/kettenbruchRekursion.c @@ -17,11 +17,11 @@ static double fractionIter0f1(const double c, const double z, unsigned int k) { abk = z / (k * ((k - 1) + c)); //abk = ak, bk - a = k > 1 ? (1 + abk) : 1; //a0, a1 - b = k > 1 ? -abk : abk; //b1 + a = k > 1 ? (1 + abk) : 1; //a0, a1 + b = k > 1 ? -abk : abk; //b1 - temp = b / (a + temp); ////bk / (ak + last result) + temp = b / (a + temp); //bk / (ak + last result) } - return a + temp; //a0 + temp + return a + temp; //a0 + temp } \ No newline at end of file diff --git a/buch/papers/0f1/listings/potenzreihe.c b/buch/papers/0f1/listings/potenzreihe.c index 3eb9b86..23fdfea 100644 --- a/buch/papers/0f1/listings/potenzreihe.c +++ b/buch/papers/0f1/listings/potenzreihe.c @@ -51,18 +51,18 @@ static double fac(int n) /** * @brief Calculates the Hypergeometric Function 0F1(;b;z) - * @param b0 in 0F1(;b0;z) - * @param z in 0F1(;b0;z) + * @param c in 0F1(;c;z) + * @param z in 0F1(;c;z) * @param n number of itertions (precision) * @return Result */ -static double powerseries(const double b, const double z, unsigned int n) +static double powerseries(const double c, const double z, unsigned int n) { double temp = 0.0; for (unsigned int k = 0; k < n; ++k) { - temp += pow(z, k) / (factorial(k) * pochhammer(b, k)); + temp += pow(z, k) / (factorial(k) * pochhammer(c, k)); } return temp; -- cgit v1.2.1