diff options
author | Runterer <37069007+Runterer@users.noreply.github.com> | 2022-08-06 11:00:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-06 11:00:54 +0200 |
commit | 72f13d47f42a7005889532fd29bcfc870f4e5051 (patch) | |
tree | 559c39cde661ea56759051c9b7965fb28468cfb6 /buch/papers/0f1/listings | |
parent | minor presentation improvements (diff) | |
parent | Merge pull request #42 from daHugen/master (diff) | |
download | SeminarSpezielleFunktionen-72f13d47f42a7005889532fd29bcfc870f4e5051.tar.gz SeminarSpezielleFunktionen-72f13d47f42a7005889532fd29bcfc870f4e5051.zip |
Merge branch 'AndreasFMueller:master' into master
Diffstat (limited to 'buch/papers/0f1/listings')
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchIterativ.c | 53 | ||||
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchRekursion.c | 27 | ||||
-rw-r--r-- | buch/papers/0f1/listings/potenzreihe.c | 69 |
3 files changed, 149 insertions, 0 deletions
diff --git a/buch/papers/0f1/listings/kettenbruchIterativ.c b/buch/papers/0f1/listings/kettenbruchIterativ.c new file mode 100644 index 0000000..d897b8f --- /dev/null +++ b/buch/papers/0f1/listings/kettenbruchIterativ.c @@ -0,0 +1,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;
+}
diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c new file mode 100644 index 0000000..3caaf43 --- /dev/null +++ b/buch/papers/0f1/listings/kettenbruchRekursion.c @@ -0,0 +1,27 @@ +/**
+ * @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 abk = 0.0;
+ double temp = 0.0;
+
+ for (; k > 0; --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)
+ }
+
+ 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..23fdfea --- /dev/null +++ b/buch/papers/0f1/listings/potenzreihe.c @@ -0,0 +1,69 @@ +#include <math.h>
+
+/**
+ * @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 c in 0F1(;c;z)
+ * @param z in 0F1(;c;z)
+ * @param n number of itertions (precision)
+ * @return Result
+ */
+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(c, k));
+ }
+
+ return temp;
+}
\ No newline at end of file |