From 26283a4a3d53f7871506ab320cbf356b2eaf4cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 26 Oct 2021 12:56:06 +0200 Subject: =?UTF-8?q?jacobiplots=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buch/chapters/110-elliptisch/images/Makefile | 28 +++- buch/chapters/110-elliptisch/images/jacobi.cpp | 154 +++++++++++++++++++++ .../chapters/110-elliptisch/images/jacobiplots.pdf | Bin 0 -> 57199 bytes .../chapters/110-elliptisch/images/jacobiplots.tex | 93 +++++++++++++ buch/chapters/110-elliptisch/images/rechteck.pdf | Bin 91630 -> 91639 bytes .../110-elliptisch/images/unvollstaendig.pdf | Bin 46390 -> 46396 bytes 6 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 buch/chapters/110-elliptisch/images/jacobi.cpp create mode 100644 buch/chapters/110-elliptisch/images/jacobiplots.pdf create mode 100644 buch/chapters/110-elliptisch/images/jacobiplots.tex diff --git a/buch/chapters/110-elliptisch/images/Makefile b/buch/chapters/110-elliptisch/images/Makefile index 5749ae0..f3f783f 100644 --- a/buch/chapters/110-elliptisch/images/Makefile +++ b/buch/chapters/110-elliptisch/images/Makefile @@ -4,7 +4,7 @@ # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule # all: lemniskate.pdf ellipsenumfang.pdf unvollstaendig.pdf rechteck.pdf \ - ellipse.pdf pendel.pdf + ellipse.pdf pendel.pdf jacobiplots.pdf lemniskate.pdf: lemniskate.tex pdflatex lemniskate.tex @@ -16,7 +16,7 @@ ekplot.tex: ellipsenumfang.m octave ellipsenumfang.m rechteck: rechteck.cpp - g++ `pkg-config --cflags gsl` `pkg-config --libs gsl` -O -Wall -g -std=c++11 rechteck.cpp -o rechteck + g++ -O -Wall -g -std=c++11 rechteck.cpp -o rechteck `pkg-config --cflags gsl` `pkg-config --libs gsl` rechteckpfade.tex: rechteck ./rechteck --outfile rechteckpfade.tex @@ -36,3 +36,27 @@ ellipse.pdf: ellipse.tex pendel.pdf: pendel.tex pdflatex pendel.tex +jacobi: jacobi.cpp + g++ -O -Wall -g -std=c++11 jacobi.cpp -o jacobi `pkg-config --cflags gsl` `pkg-config --libs gsl` + +test: blubb.tex + +blubb.tex: jacobi + ./jacobi --umax=14 --outfile=blubb.tex blubb 0.7 + +jacobipaths.tex: jacobi Makefile + ./jacobi --umax=13 --steps=200 --outfile=jacobipaths.tex \ + zero 0.00 \ + one 0.2 \ + two 0.4 \ + three 0.6 \ + four 0.8 \ + five 0.9 \ + six 0.99 \ + seven 0.999 \ + eight 0.9999 \ + nine 0.99999 \ + ten 1.0 + +jacobiplots.pdf: jacobiplots.tex jacobipaths.tex + pdflatex jacobiplots.tex diff --git a/buch/chapters/110-elliptisch/images/jacobi.cpp b/buch/chapters/110-elliptisch/images/jacobi.cpp new file mode 100644 index 0000000..438fe48 --- /dev/null +++ b/buch/chapters/110-elliptisch/images/jacobi.cpp @@ -0,0 +1,154 @@ +/* + * jacobi.cpp + * + * (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace jacobi { + +static struct option longopts[] { +{ "k", required_argument, NULL, 'k' }, +{ "m", required_argument, NULL, 'm' }, +{ "outfile", required_argument, NULL, 'o' }, +{ "infile", required_argument, NULL, 'i' }, +{ "umin", required_argument, NULL, 'f' }, +{ "umax", required_argument, NULL, 't' }, +{ "steps", required_argument, NULL, 's' }, +{ NULL, 0, NULL, 0 } +}; + +/** + * \brief A class to contain a single plot + */ +class jacobiplot : public std::vector > { + std::string punkt(std::pair x) const { + char buffer[128]; + snprintf(buffer, sizeof(buffer), "({%.4f*\\dx},{%.4f*\\dy})", + x.first, x.second); + return std::string(buffer); + } +public: + jacobiplot() { } + void write(std::ostream& out, const std::string& name) const { + out << "\\def\\" << name << "{" << std::endl; + auto i = begin(); + out << punkt(*i); + for (i++; i != end(); i++) { + out << std::endl << " -- " << punkt(*i); + } + out << std::endl << "}" << std::endl; + } +}; + +/** + * \brief A class containing all three basic functions + */ +class jacobiplots { + jacobiplot _sn; + jacobiplot _cn; + jacobiplot _dn; + double _m; +public: + const jacobiplot& sn() const { return _sn; } + const jacobiplot& cn() const { return _cn; } + const jacobiplot& dn() const { return _dn; } + jacobiplots(double m) : _m(m) { } + double m() const { return _m; } + void add(double umin, double umax, int steps) { + _sn.clear(); + _cn.clear(); + _dn.clear(); + double h = (umax - umin) / steps; + for (int i = 0; i <= steps; i++) { + double u = umin + i * h; + double snvalue, cnvalue, dnvalue; + gsl_sf_elljac_e(u, m(), &snvalue, &cnvalue, &dnvalue); + _sn.push_back(std::make_pair(u, snvalue)); + _cn.push_back(std::make_pair(u, cnvalue)); + _dn.push_back(std::make_pair(u, dnvalue)); + } + } + void write(std::ostream& out, const std::string& name) const { + out << "% name=" << name << ", m=" << m() << std::endl; + out << "\\def\\m" << name << "{" << m() << "}" << std::endl; + _sn.write(out, std::string("sn") + name); + _cn.write(out, std::string("cn") + name); + _dn.write(out, std::string("dn") + name); + } +}; + +int main(int argc, char *argv[]) { + int c; + int longindex; + std::ostream *out = &std::cout; + std::string infilename; + int steps = 100; + double umin = 0; + double umax = 10; + while (EOF != (c = getopt_long(argc, argv, "o:i:f:t:s:", longopts, + &longindex))) + switch (c) { + case 'o': + out = new std::ofstream(optarg); + (*out) << "%" << std::endl; + (*out) << "% " << optarg << std::endl; + (*out) << "%" << std::endl; + break; + case 'i': + infilename = std::string(optarg); + break; + case 'f': + umin = std::stod(optarg); + break; + case 't': + umax = std::stod(optarg); + break; + case 's': + steps = std::stoi(optarg); + break; + } + + if (infilename.size() == 0) { + while ((optind + 1) < argc) { + std::string name(argv[optind++]); + double m = std::stod(argv[optind++]); + jacobiplots j(m); + j.add(umin, umax, steps); + j.write(*out, name); + } + } else { + std::ifstream infile(infilename); + while (!infile.eof()) { + std::string name; + double m; + infile >> name; + infile >> m; + jacobiplots j(m); + j.add(umin, umax, steps); + j.write(*out, name); + } + } + + return EXIT_SUCCESS; +} + +} // namespace jacobi + +int main(int argc, char *argv[]) { + try { + return jacobi::main(argc, argv); + } catch (const std::exception& x) { + std::cerr << "cannot build sn/cn/dn file: " << x.what(); + std::cerr << std::endl; + } + return EXIT_FAILURE; +} diff --git a/buch/chapters/110-elliptisch/images/jacobiplots.pdf b/buch/chapters/110-elliptisch/images/jacobiplots.pdf new file mode 100644 index 0000000..c1885c9 Binary files /dev/null and b/buch/chapters/110-elliptisch/images/jacobiplots.pdf differ diff --git a/buch/chapters/110-elliptisch/images/jacobiplots.tex b/buch/chapters/110-elliptisch/images/jacobiplots.tex new file mode 100644 index 0000000..4fc572e --- /dev/null +++ b/buch/chapters/110-elliptisch/images/jacobiplots.tex @@ -0,0 +1,93 @@ +% +% jacobiplots.tex -- template for standalon tikz images +% +% (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule +% +\documentclass[tikz]{standalone} +\usepackage{amsmath} +\usepackage{times} +\usepackage{txfonts} +\usepackage{pgfplots} +\usepackage{csvsimple} +\usetikzlibrary{arrows,intersections,math} +\begin{document} +\def\skala{1} +\def\dx{1} +\def\dy{2} +\definecolor{darkgreen}{rgb}{0,0.6,0} +\input{jacobipaths.tex} +\def\piticks{ + \draw (3.1415,-0.1) -- (3.1415,0.1); + \node at (3.1415,0) [below] {$\pi$}; + \draw (6.2831,-0.1) -- (6.2831,0.1); + \node at (6.2831,0) [below] {$2\pi$}; + \draw (9.4248,-0.1) -- (9.4248,0.1); + \node at (9.4248,0) [below] {$3\pi$}; + \draw (12.5664,-0.1) -- (12.5664,0.1); + \node at (12.5664,0) [below] {$4\pi$}; +} +\def\mlabel#1{ +%\fill[color=gray!50] (-0.2,-6) rectangle (7.0,2.3); +\fill[color=gray!50] (-0.2,1.65) rectangle (7.0,2.3); +\draw[line width=0.5pt] (-0.2,-6) rectangle (7.0,2.3); +\begin{scope}[scale=0.5] +\node at (6.5,{\dy+2}) {$m = #1$}; +\end{scope} +} +\def\jacobiplot#1#2#3#4{ + + +\begin{scope}[scale=0.5] +\draw[->] (-0.1,0) -- (13.5,0) coordinate[label={$u$}]; +\piticks +\draw[->] (0,-2.1) -- (0,2.5) coordinate[label={right:$\operatorname{sn}(u,k)$}]; +\draw[color=red#4] #1; +\end{scope} + +\begin{scope}[yshift=-2.5cm,scale=0.5] +\draw[->] (-0.1,0) -- (13.5,0) coordinate[label={$u$}]; +\piticks +\draw[->] (0,-2.1) -- (0,2.5) coordinate[label={right:$\operatorname{cn}(u,k)$}]; +\draw[color=blue#4] #2; +\end{scope} + +\begin{scope}[yshift=-5.5cm,scale=0.5] +\draw[->] (-0.1,0) -- (13.5,0) coordinate[label={$u$}]; +\piticks +\draw[->] (0,-0.1) -- (0,3.5) coordinate[label={right:$\operatorname{dn}(u,k)$}]; +\draw[color=darkgreen#4] #3; +\end{scope} + +} +%\input{blubb.tex} +\begin{tikzpicture}[>=latex,thick,scale=\skala] + +\begin{scope} +\mlabel{\mone} +\jacobiplot{\snzero}{\cnzero}{\dnzero}{!50} +\jacobiplot{\snone}{\cnone}{\dnone}{} +\end{scope} + +\begin{scope}[xshift=7.3cm] +\mlabel{\mfive} +\jacobiplot{\snzero}{\cnzero}{\dnzero}{!50} +\jacobiplot{\snfive}{\cnfive}{\dnfive}{} +\end{scope} + +\begin{scope}[xshift=0cm,yshift=-8.4cm] +\mlabel{\mseven} +\jacobiplot{\snzero}{\cnzero}{\dnzero}{!50} +%\jacobiplot{\sneight}{\cneight}{\dneight}{} +\jacobiplot{\snseven}{\cnseven}{\dnseven}{} +\end{scope} + +\begin{scope}[xshift=7.3cm,yshift=-8.4cm] +\mlabel{\mnine} +\jacobiplot{\snzero}{\cnzero}{\dnzero}{!50} +\jacobiplot{\snnine}{\cnnine}{\dnnine}{} +\end{scope} + + +\end{tikzpicture} +\end{document} + diff --git a/buch/chapters/110-elliptisch/images/rechteck.pdf b/buch/chapters/110-elliptisch/images/rechteck.pdf index ea5869d..6209897 100644 Binary files a/buch/chapters/110-elliptisch/images/rechteck.pdf and b/buch/chapters/110-elliptisch/images/rechteck.pdf differ diff --git a/buch/chapters/110-elliptisch/images/unvollstaendig.pdf b/buch/chapters/110-elliptisch/images/unvollstaendig.pdf index f28495c..491f328 100644 Binary files a/buch/chapters/110-elliptisch/images/unvollstaendig.pdf and b/buch/chapters/110-elliptisch/images/unvollstaendig.pdf differ -- cgit v1.2.1