aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/070-orthogonalitaet
diff options
context:
space:
mode:
authorAndreas Müller <andreas.mueller@ost.ch>2022-01-08 17:42:29 +0100
committerAndreas Müller <andreas.mueller@ost.ch>2022-01-08 17:42:29 +0100
commit9164518de7acc0a4124ab78872fc376c1bb4e625 (patch)
tree261385afc6d5121fbbe732743e041f665bd9691b /buch/chapters/070-orthogonalitaet
parentPole und Nullstellen der Gewichtsfunktion (diff)
downloadSeminarSpezielleFunktionen-9164518de7acc0a4124ab78872fc376c1bb4e625.tar.gz
SeminarSpezielleFunktionen-9164518de7acc0a4124ab78872fc376c1bb4e625.zip
add jacobi illustration
Diffstat (limited to 'buch/chapters/070-orthogonalitaet')
-rw-r--r--buch/chapters/070-orthogonalitaet/images/Makefile13
-rw-r--r--buch/chapters/070-orthogonalitaet/images/jacobi.cpp179
-rw-r--r--buch/chapters/070-orthogonalitaet/images/jacobi.pdfbin0 -> 65748 bytes
-rw-r--r--buch/chapters/070-orthogonalitaet/images/jacobi.tex104
4 files changed, 295 insertions, 1 deletions
diff --git a/buch/chapters/070-orthogonalitaet/images/Makefile b/buch/chapters/070-orthogonalitaet/images/Makefile
index 900ae7f..efe5d36 100644
--- a/buch/chapters/070-orthogonalitaet/images/Makefile
+++ b/buch/chapters/070-orthogonalitaet/images/Makefile
@@ -4,7 +4,7 @@
#
# (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
#
-all: legendre.pdf orthogonal.pdf weight.pdf
+all: legendre.pdf orthogonal.pdf weight.pdf jacobi.pdf
legendrepaths.tex: legendre.m
octave legendre.m
@@ -19,3 +19,14 @@ weight.pdf: weight.tex weightfunction.tex
weightfunction.tex: weight.m
octave weight.m
+jacobi: jacobi.cpp
+ g++ --std=c++11 -O -Wall -g -o jacobi jacobi.cpp
+
+jacobipaths.tex: jacobi Makefile
+ ./jacobi --a=0 --b=0 --prefix=legendre --outfile=jacobipaths.tex
+ ./jacobi --a=1 --b=0 --degree=14 --prefix=aone >> jacobipaths.tex
+ ./jacobi --a=2 --b=0 --prefix=atwo >> jacobipaths.tex
+ ./jacobi --a=-1 --b=0 --degree=14 --prefix=aminusone >> jacobipaths.tex
+ ./jacobi --a=-2 --b=0 --prefix=aminustwo >> jacobipaths.tex
+jacobi.pdf: jacobi.tex jacobipaths.tex
+ pdflatex jacobi.tex
diff --git a/buch/chapters/070-orthogonalitaet/images/jacobi.cpp b/buch/chapters/070-orthogonalitaet/images/jacobi.cpp
new file mode 100644
index 0000000..e010fd6
--- /dev/null
+++ b/buch/chapters/070-orthogonalitaet/images/jacobi.cpp
@@ -0,0 +1,179 @@
+/*
+ * jacobi.cpp
+ *
+ * (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+ */
+#include <cstdlib>
+#include <vector>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <memory>
+#include <getopt.h>
+#include <cmath>
+
+/**
+ * \brief Pfad-Klasse
+ */
+class pfad {
+ std::ostringstream *_inhalt;
+ std::string _name;
+ int _punkte;
+public:
+ pfad(const pfad&) = delete;
+ pfad(const std::string name) : _name(name), _punkte(0) {
+ _inhalt = new std::ostringstream();
+ }
+ ~pfad() {
+ if (_inhalt) {
+ delete _inhalt;
+ }
+ }
+ void add(const std::pair<double,double>& XY) {
+ if (_punkte == 0) {
+ *_inhalt << "\\def\\" + _name + "{\n\t";
+ } else {
+ *_inhalt << "\n\t-- ";
+ }
+ *_inhalt << "({";
+ *_inhalt << XY.first;
+ *_inhalt << "*\\dx},{";
+ *_inhalt << XY.second;
+ *_inhalt << "*\\dy})";
+ _punkte++;
+ }
+ void operator()(const std::pair<double,double>& XY) {
+ add(XY);
+ }
+ std::string macro() const {
+ std::string result = _inhalt->str();
+ result = result + ";\n}\n";
+ return result;
+ }
+};
+typedef std::shared_ptr<pfad> pfad_ptr;
+
+#define c(k) ((k)+a+b)
+
+std::vector<double> jacobiP(double a, double b, double x, int n) {
+ std::vector<double> result;
+ double p0 = 1.;
+ result.push_back(p0);
+ double p1 = (a - b)/2. + (1. + (a + b)/2.) * x;
+ result.push_back(p1);
+ int i = 1;
+ while (i++ < n) {
+ double p;
+ p = c(2*i-1) * (c(2*i-2) * c(2*i) * x + a*a - b*b) * p1
+ - 2. * (i-1.+a) * (i-1.+b) * c(2*i) * p0;
+ p /= 2 * i * c(i) * c(2*i-2);
+ result.push_back(p);
+ p0 = p1;
+ p1 = p;
+ }
+ return result;
+}
+
+std::string jacobiPlots(const std::string& prefix,
+ double a, double b, int n, int N) {
+ std::vector<pfad_ptr> pfade;
+ for (int j = 0; j <= n; j++) {
+ char c = 'a' + j;
+ std::string name = prefix;
+ name.append(1, c);
+ pfad_ptr p(new pfad(name));
+ pfade.push_back(p);
+ }
+ for (int i = -N; i <= N; i++) {
+ double x = i / (double)N;
+ std::vector<double> r = jacobiP(a, b, x, n);
+ for (int j = 0; j <= n; j++) {
+ std::pair<double,double> XY
+ = std::make_pair(x, r[j]);
+ pfade[j]->add(XY);
+ }
+ }
+ std::ostringstream result;
+ for (int j = 0; j <= n; j++) {
+ result << pfade[j]->macro();
+ }
+ return result.str();
+}
+
+std::string jacobiWeight(const std::string& prefix,
+ double a, double b, int N) {
+ std::ostringstream out;
+ out << "\\def\\" << prefix << "weight{" << std::endl;
+ int _punkte = 0;
+ int starti = -N;
+ int endi = N;
+ if (b < 0) {
+ starti += 1;
+ }
+ if (a < 0) {
+ endi -= 1;
+ }
+ for (int i = starti; i <= endi; i++) {
+ double x = i / (double)N;
+ double y = pow(1-x, a) * pow(1+x, b);
+ if (_punkte > 0) {
+ out << std::endl << "\t-- ";
+ }
+ out << "({" << x << "*\\dx},{" << y << "*\\dwy})";
+ _punkte++;
+ }
+ out << std::endl << "}" << std::endl;
+ return out.str();
+}
+
+struct option options[] = {
+{ "a", required_argument, NULL, 'a' },
+{ "b", required_argument, NULL, 'b' },
+{ "degree", required_argument, NULL, 'n' },
+{ "points", required_argument, NULL, 'N' },
+{ "prefix", required_argument, NULL, 'p' },
+{ "outfile", required_argument, NULL, 'o' },
+{ NULL, 0, NULL, 0 }
+};
+
+int main(int argc, char *argv[]) {
+ int n = 10;
+ int N = 100;
+ double a = 1;
+ double b = 1;
+ std::string outfilename;
+ std::string prefix("prefix");
+ int c;
+ while (EOF != (c = getopt_long(argc, argv, "a:b:n:N:o:p:", options,
+ NULL)))
+ switch (c) {
+ case 'a':
+ a = std::stod(optarg);
+ break;
+ case 'b':
+ b = std::stod(optarg);
+ break;
+ case 'n':
+ n = std::stoi(optarg);
+ break;
+ case 'N':
+ N = std::stoi(optarg);
+ break;
+ case 'o':
+ outfilename = std::string(optarg);
+ break;
+ case 'p':
+ prefix = std::string(optarg);
+ break;
+ }
+ std::string result = jacobiPlots(prefix, a, b, n, N);
+ result.append(jacobiWeight(prefix, a, b, N));
+ if (outfilename.size() == 0) {
+ std::cout << result;
+ return EXIT_SUCCESS;
+ }
+ std::ofstream out(outfilename.c_str());
+ out << result;
+ out.close();
+ return EXIT_SUCCESS;
+}
diff --git a/buch/chapters/070-orthogonalitaet/images/jacobi.pdf b/buch/chapters/070-orthogonalitaet/images/jacobi.pdf
new file mode 100644
index 0000000..8eb4f09
--- /dev/null
+++ b/buch/chapters/070-orthogonalitaet/images/jacobi.pdf
Binary files differ
diff --git a/buch/chapters/070-orthogonalitaet/images/jacobi.tex b/buch/chapters/070-orthogonalitaet/images/jacobi.tex
new file mode 100644
index 0000000..7d2853f
--- /dev/null
+++ b/buch/chapters/070-orthogonalitaet/images/jacobi.tex
@@ -0,0 +1,104 @@
+%
+% jacobi.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}
+\input{jacobipaths.tex}
+\begin{tikzpicture}[>=latex,thick,scale=\skala]
+
+\def\dx{6}
+\def\dy{2}
+\def\dwy{1}
+
+\begin{scope}
+ \begin{scope}
+ \clip (-6,-2.55) rectangle (6,2.55);
+ \fill[color=red!20] \legendreweight
+ -- ({1*\dx},0) -- ({-1*\dx},0) -- cycle;
+ %\draw[color=blue] \legendrea;
+ \draw[color=blue] \legendreb;
+ \draw[color=blue] \legendrec;
+ \draw[color=blue] \legendred;
+ \draw[color=blue] \legendree;
+ \draw[color=blue] \legendref;
+ \draw[color=blue] \legendreg;
+ \draw[color=blue] \legendreh;
+ \draw[color=blue] \legendrei;
+ \draw[color=blue] \legendrek;
+ \draw[color=red] \legendreweight;
+ \end{scope}
+ \draw[->] (-6.1,0) -- (6.1,0) coordinate[label={$x$}];
+ \draw[->] (0,-2.55) -- (0,2.6) coordinate[label={right:$y$}];
+ \node at (6,2.3) [left] {$a=0$};
+ \node at (-6,2.3) [right] {$b=0$};
+\end{scope}
+
+\begin{scope}[yshift=-5.6cm]
+ \begin{scope}
+ \clip (-6,-2.55) rectangle (6,2.55);
+ \fill[color=red!20] \aoneweight
+ -- ({1*\dx},0) -- ({-1*\dx},0) -- cycle;
+ %\draw[color=blue] \aonea;
+ \draw[color=blue] \aoneb;
+ \draw[color=blue] \aonec;
+ \draw[color=blue] \aoned;
+ \draw[color=blue] \aonee;
+ \draw[color=blue] \aonef;
+ \draw[color=blue] \aoneg;
+ \draw[color=blue] \aoneh;
+ \draw[color=blue] \aonei;
+ \draw[color=blue] \aonek;
+ \draw[color=blue] \aonel;
+ \draw[color=blue] \aonem;
+ \draw[color=blue] \aonen;
+ \draw[color=blue] \aoneo;
+ \draw[color=red] \aoneweight;
+ \end{scope}
+ \draw[->] (-6.1,0) -- (6.1,0) coordinate[label={$x$}];
+ \draw[->] (0,-2.55) -- (0,2.6) coordinate[label={right:$y$}];
+ \node at (6,2.3) [left] {$a=1$};
+ \node at (-6,2.3) [right] {$b=0$};
+\end{scope}
+
+\begin{scope}[yshift=-11.2cm]
+ \begin{scope}
+ \clip (-6,-2.55) rectangle (6,2.55);
+ \fill[color=red!20] \aminusoneweight
+ -- ({1*\dx},3)
+ -- ({1*\dx},0) -- ({-1*\dx},0) -- cycle;
+ %\draw[color=blue] \aminusonea;
+ \draw[color=blue] \aminusoneb;
+ \draw[color=blue] \aminusonec;
+ \draw[color=blue] \aminusoned;
+ \draw[color=blue] \aminusonee;
+ \draw[color=blue] \aminusonef;
+ \draw[color=blue] \aminusoneg;
+ \draw[color=blue] \aminusoneh;
+ \draw[color=blue] \aminusonei;
+ \draw[color=blue] \aminusonek;
+ \draw[color=blue] \aminusonel;
+ \draw[color=blue] \aminusonem;
+ \draw[color=blue] \aminusonen;
+ \draw[color=blue] \aminusoneo;
+ \draw[color=red] \aminusoneweight;
+ \end{scope}
+ \draw[->] (-6.1,0) -- (6.1,0) coordinate[label={$x$}];
+ \draw[->] (0,-2.55) -- (0,2.6) coordinate[label={right:$y$}];
+ \node at (6,2.3) [left] {$a=-1$};
+ \node at (-6,2.3) [right] {$b=0$};
+\end{scope}
+
+
+
+\end{tikzpicture}
+\end{document}
+