From bfd6e3d56f2e91f81b42c811fbff62abc153724d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Sat, 16 Oct 2021 10:09:16 +0200 Subject: new files --- buch/chapters/110-elliptisch/images/rechteck.cpp | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 buch/chapters/110-elliptisch/images/rechteck.cpp (limited to 'buch/chapters/110-elliptisch/images/rechteck.cpp') diff --git a/buch/chapters/110-elliptisch/images/rechteck.cpp b/buch/chapters/110-elliptisch/images/rechteck.cpp new file mode 100644 index 0000000..6bd6a06 --- /dev/null +++ b/buch/chapters/110-elliptisch/images/rechteck.cpp @@ -0,0 +1,54 @@ +/* + * rechteck.cpp + * + * (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule + */ +#include +#include +#include +#include +#include + +double ast = 1; + +std::complex integrand(double k, const std::complex& z) { + std::complex s = z * z; + std::complex eins(1); + std::complex result = eins / sqrt((eins - s) * (eins - k * k * s)); + return ast * ((result.imag() < 0) ? -result : result); +} + +std::complex segment(double k, const std::complex& z1, + const std::complex& z2, int n = 100) { + std::complex dz = z2 - z1; + std::complex summe(0); + double h = 1. / n; + summe = integrand(k, z1); + summe += integrand(k, z2); + for (int i = 1; i < n; i++) { + double t = i * h; + std::complex z = (1 - t) * z1 + t * z2; + summe += 2. * integrand(k, z); + } + return dz * h * summe / 2.; +} + +int main(int argc, char *argv[]) { + double k = 0.5; + double y = -0.0001; + double xstep = -0.1; + ast = 1; + std::complex z(0, y); + std::complex w = segment(k, std::complex(0), z); + std::cout << z << std::endl; + int counter = 100; + while (counter-- > 0) { + std::complex znext = z + std::complex(xstep); + std::complex incr = segment(k, z, znext); + w += incr; + std::cout << znext << " -> " << w << ", "; + std::cout << integrand(k, znext) << std::endl; + z = znext; + } + return EXIT_SUCCESS; +} -- cgit v1.2.1