diff options
author | Fabian <@> | 2022-08-13 22:27:32 +0200 |
---|---|---|
committer | Fabian <@> | 2022-08-13 22:27:32 +0200 |
commit | 1a65f1e2cc20e1dfe5d0d88cf42ee7355c20b1ff (patch) | |
tree | 27bf080b62592894cbcd73b7673cb328f11da250 /buch/papers/0f1/listings | |
parent | 2. Ueberarbeitung, Referenzen (diff) | |
download | SeminarSpezielleFunktionen-1a65f1e2cc20e1dfe5d0d88cf42ee7355c20b1ff.tar.gz SeminarSpezielleFunktionen-1a65f1e2cc20e1dfe5d0d88cf42ee7355c20b1ff.zip |
2. Ueberarbeitung
Diffstat (limited to 'buch/papers/0f1/listings')
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchIterativ.c | 60 | ||||
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchRekursion.c | 60 |
2 files changed, 60 insertions, 60 deletions
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;
+}
|