diff options
author | Nicolas Tobler <nicolas.tobler@ost.ch> | 2022-08-23 22:33:40 +0200 |
---|---|---|
committer | Nicolas Tobler <nicolas.tobler@ost.ch> | 2022-08-23 22:33:40 +0200 |
commit | 6ac6dd132a11abd9ec4955cd2e35e22408c982e6 (patch) | |
tree | 902445b16ec2f2b9df3b3659b6139926469c267f /buch/papers/0f1/listings/kettenbruchIterativ.c | |
parent | Added Berechnung der rationalen Funktion (diff) | |
parent | Merge pull request #63 from NaoPross/master (diff) | |
download | SeminarSpezielleFunktionen-6ac6dd132a11abd9ec4955cd2e35e22408c982e6.tar.gz SeminarSpezielleFunktionen-6ac6dd132a11abd9ec4955cd2e35e22408c982e6.zip |
Merge branch 'master' of https://github.com/AndreasFMueller/SeminarSpezielleFunktionen
Diffstat (limited to '')
-rw-r--r-- | buch/papers/0f1/listings/kettenbruchIterativ.c | 60 |
1 files changed, 17 insertions, 43 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 |