aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/040-rekursion/gammalimit
diff options
context:
space:
mode:
authorSamuel Niederer <43746162+samnied@users.noreply.github.com>2022-07-24 12:17:00 +0200
committerGitHub <noreply@github.com>2022-07-24 12:17:00 +0200
commitefe7c35759afb5cbae3c1683873c5159be0be09f (patch)
tree84f2e8510132352f9943bddc577ccf32cd46f2dc /buch/chapters/040-rekursion/gammalimit
parentadd current work (diff)
parentMerge pull request #26 from p1mueller/master (diff)
downloadSeminarSpezielleFunktionen-efe7c35759afb5cbae3c1683873c5159be0be09f.tar.gz
SeminarSpezielleFunktionen-efe7c35759afb5cbae3c1683873c5159be0be09f.zip
Merge branch 'AndreasFMueller:master' into master
Diffstat (limited to 'buch/chapters/040-rekursion/gammalimit')
-rw-r--r--buch/chapters/040-rekursion/gammalimit/Makefile11
-rw-r--r--buch/chapters/040-rekursion/gammalimit/l.cpp26
-rw-r--r--buch/chapters/040-rekursion/gammalimit/l.m19
3 files changed, 56 insertions, 0 deletions
diff --git a/buch/chapters/040-rekursion/gammalimit/Makefile b/buch/chapters/040-rekursion/gammalimit/Makefile
new file mode 100644
index 0000000..0804e74
--- /dev/null
+++ b/buch/chapters/040-rekursion/gammalimit/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile -- build gamma limit test programm
+#
+# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+#
+l: l.cpp
+ g++ -O2 -g -Wall `pkg-config --cflags gsl` `pkg-config --libs gsl` \
+ -o l l.cpp
+
+test: l
+ ./l
diff --git a/buch/chapters/040-rekursion/gammalimit/l.cpp b/buch/chapters/040-rekursion/gammalimit/l.cpp
new file mode 100644
index 0000000..7a86800
--- /dev/null
+++ b/buch/chapters/040-rekursion/gammalimit/l.cpp
@@ -0,0 +1,26 @@
+/*
+ * l.cpp
+ *
+ * (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+ */
+#include <cstdlib>
+#include <cmath>
+#include <cstdio>
+
+int main(int argc, char *argv[]) {
+ double x = 0.5;
+ double g = tgamma(x);
+ printf("limit: %20.16f\n", g);
+ double p = 1;
+ long long N = 100000000000;
+ long long n = 10;
+ for (long long k = 1; k <= N; k++) {
+ p = p * k / (x + k - 1);
+ if (0 == k % n) {
+ double gval = p * pow(k, x-1);
+ printf("%12ld %20.16f %20.16f\n", k, gval, gval - g);
+ n = n * 10;
+ }
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/buch/chapters/040-rekursion/gammalimit/l.m b/buch/chapters/040-rekursion/gammalimit/l.m
new file mode 100644
index 0000000..32b6442
--- /dev/null
+++ b/buch/chapters/040-rekursion/gammalimit/l.m
@@ -0,0 +1,19 @@
+#
+# l.m -- Berechnung der Gamma-Funktion
+#
+# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+#
+global N;
+N = 10000;
+
+function retval = gamma(x, n)
+ p = 1;
+ for k = (1:n)
+ p = p * k / (x + k - 1);
+ end
+ retval = p * n^(x-1);
+endfunction
+
+for n = (100:100:N)
+ printf("Gamma(%4d) = %10f\n", n, gamma(0.5, n));
+end