aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/0f1/listings/kettenbruchIterativ.c
diff options
context:
space:
mode:
authorPatrik Müller <36931350+p1mueller@users.noreply.github.com>2022-07-25 10:07:38 +0200
committerGitHub <noreply@github.com>2022-07-25 10:07:38 +0200
commit65692efda98ddc227db40aa181ee20aee1696010 (patch)
tree9214ba6c07c0bd0281a0c043180bd419607643fc /buch/papers/0f1/listings/kettenbruchIterativ.c
parentAdd missing explanations, correct typos, mention sign change of LP earlier (diff)
parentfix brace-problem (diff)
downloadSeminarSpezielleFunktionen-65692efda98ddc227db40aa181ee20aee1696010.tar.gz
SeminarSpezielleFunktionen-65692efda98ddc227db40aa181ee20aee1696010.zip
Merge branch 'AndreasFMueller:master' into master
Diffstat (limited to 'buch/papers/0f1/listings/kettenbruchIterativ.c')
-rw-r--r--buch/papers/0f1/listings/kettenbruchIterativ.c45
1 files changed, 45 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..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;
+}