From 335c3a23f09759be380291ec89b0f2c43c2d3db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Sat, 25 Jun 2022 22:46:16 +0200 Subject: fix agm --- buch/chapters/110-elliptisch/agm/agm.cpp | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 buch/chapters/110-elliptisch/agm/agm.cpp (limited to 'buch/chapters/110-elliptisch/agm/agm.cpp') diff --git a/buch/chapters/110-elliptisch/agm/agm.cpp b/buch/chapters/110-elliptisch/agm/agm.cpp new file mode 100644 index 0000000..fdb0441 --- /dev/null +++ b/buch/chapters/110-elliptisch/agm/agm.cpp @@ -0,0 +1,42 @@ +/* + * agm.cpp + * + * (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule + */ +#include +#include +#include +#include +#include + + + +int main(int argc, char *argv[]) { + long double a = 1; + long double b = sqrtl(2.)/2; + if (argc >= 3) { + a = std::stod(argv[1]); + b = std::stod(argv[2]); + } + + { + long double an = a; + long double bn = b; + for (int i = 0; i < 10; i++) { + printf("%d %24.18Lf %24.18Lf %24.18Lf\n", + i, an, bn, a * M_PI / (2 * an)); + long double A = (an + bn) / 2; + bn = sqrtl(an * bn); + an = A; + } + } + + { + double k = b/a; + k = sqrt(1 - k*k); + double K = gsl_sf_ellint_Kcomp(k, GSL_PREC_DOUBLE); + printf(" %24.18f %24.18f\n", k, K); + } + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From 05d75b0f467b2535db538ecaee461cf0c8b637d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Mon, 27 Jun 2022 20:17:16 +0200 Subject: add stuff for elliptic filters --- buch/chapters/110-elliptisch/agm/agm.cpp | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'buch/chapters/110-elliptisch/agm/agm.cpp') diff --git a/buch/chapters/110-elliptisch/agm/agm.cpp b/buch/chapters/110-elliptisch/agm/agm.cpp index fdb0441..8abb4b2 100644 --- a/buch/chapters/110-elliptisch/agm/agm.cpp +++ b/buch/chapters/110-elliptisch/agm/agm.cpp @@ -9,23 +9,54 @@ #include #include +inline long double sqrl(long double x) { + return x * x; +} +long double Xn(long double a, long double b, long double x) { + double long epsilon = fabsl(a - b); + if (epsilon > 0.001) { + return (a - sqrtl(sqrl(a) - sqrl(x) * (a + b) * (a - b))) + / (x * (a - b)); + } + long double d = a + b; + long double x1 = 0; + long double y2 = sqrl(x/a); + long double c = 1; + long double s = 0; + int k = 1; + while (c > 0.0000000000001) { + c *= (0.5 - (k - 1)) / k; + c *= (d - epsilon) * y2; + s += c; + c *= epsilon; + c = -c; + k++; + } + return s * a / x; +} int main(int argc, char *argv[]) { long double a = 1; long double b = sqrtl(2.)/2; + long double x = 0.7; if (argc >= 3) { a = std::stod(argv[1]); b = std::stod(argv[2]); } + if (argc >= 4) { + x = std::stod(argv[3]); + } { long double an = a; long double bn = b; + long double xn = x; for (int i = 0; i < 10; i++) { - printf("%d %24.18Lf %24.18Lf %24.18Lf\n", - i, an, bn, a * M_PI / (2 * an)); + printf("%d %24.18Lf %24.18Lf %24.18Lf %24.18Lf\n", + i, an, bn, xn, a * asin(xn) / an); long double A = (an + bn) / 2; + xn = Xn(an, bn, xn); bn = sqrtl(an * bn); an = A; } @@ -36,6 +67,8 @@ int main(int argc, char *argv[]) { k = sqrt(1 - k*k); double K = gsl_sf_ellint_Kcomp(k, GSL_PREC_DOUBLE); printf(" %24.18f %24.18f\n", k, K); + double F = gsl_sf_ellint_F(asinl(x), k, GSL_PREC_DOUBLE); + printf(" %24.18f %24.18f\n", k, F); } return EXIT_SUCCESS; -- cgit v1.2.1