From f5047d4d780e996a8b8f7738c1ac7c884a07f135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Sun, 13 Mar 2022 23:26:58 +0100 Subject: new stuff about beta, test2 --- buch/chapters/040-rekursion/Makefile.inc | 1 + buch/chapters/040-rekursion/beta.tex | 104 +++--------- buch/chapters/040-rekursion/images/Makefile | 16 +- buch/chapters/040-rekursion/images/beta.pdf | Bin 0 -> 109772 bytes buch/chapters/040-rekursion/images/beta.tex | 236 ++++++++++++++++++++++++++ buch/chapters/040-rekursion/images/betadist.m | 58 +++++++ buch/chapters/040-rekursion/images/order.m | 119 +++++++++++++ buch/chapters/040-rekursion/images/order.pdf | Bin 0 -> 32692 bytes buch/chapters/040-rekursion/images/order.tex | 125 ++++++++++++++ 9 files changed, 574 insertions(+), 85 deletions(-) create mode 100644 buch/chapters/040-rekursion/images/beta.pdf create mode 100644 buch/chapters/040-rekursion/images/beta.tex create mode 100644 buch/chapters/040-rekursion/images/betadist.m create mode 100644 buch/chapters/040-rekursion/images/order.m create mode 100644 buch/chapters/040-rekursion/images/order.pdf create mode 100644 buch/chapters/040-rekursion/images/order.tex (limited to 'buch/chapters/040-rekursion') diff --git a/buch/chapters/040-rekursion/Makefile.inc b/buch/chapters/040-rekursion/Makefile.inc index ed8fd51..a222b1c 100644 --- a/buch/chapters/040-rekursion/Makefile.inc +++ b/buch/chapters/040-rekursion/Makefile.inc @@ -9,6 +9,7 @@ CHAPTERFILES = $(CHAPTERFILES) \ chapters/040-rekursion/bohrmollerup.tex \ chapters/040-rekursion/integral.tex \ chapters/040-rekursion/beta.tex \ + chapters/040-rekursion/betaverteilung.tex \ chapters/040-rekursion/linear.tex \ chapters/040-rekursion/hypergeometrisch.tex \ chapters/040-rekursion/uebungsaufgaben/401.tex \ diff --git a/buch/chapters/040-rekursion/beta.tex b/buch/chapters/040-rekursion/beta.tex index ea847bc..ff59bad 100644 --- a/buch/chapters/040-rekursion/beta.tex +++ b/buch/chapters/040-rekursion/beta.tex @@ -3,11 +3,17 @@ % % (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule % -\subsection{Die Beta-Funktion -\label{buch:rekursion:gamma:subsection:beta}} +\section{Die Beta-Funktion +\label{buch:rekursion:gamma:section:beta}} Die Eulersche Integralformel für die Gamma-Funktion in -Definition~\ref{buch:rekursion:def:gamma} wurde bisher nicht -gerechtfertigt. +Definition~\ref{buch:rekursion:def:gamma} wurde in +Abschnitt~\ref{buch:subsection:integral-eindeutig} +mit dem Satz von Mollerup gerechtfertigt. +Man kann Sie aber auch als Grenzfall der Beta-Funktion verstehen, +die in diesem Abschnitt dargestellt wird. + + +\subsection{Beta-Integral} In diesem Abschnitt wird das Beta-Integral eingeführt, eine Funktion von zwei Variablen, welches eine Integral-Definition mit einer reichaltigen Menge von Rekursionsbeziehungen hat, die sich direkt auf @@ -233,6 +239,16 @@ B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} berechnet werden. \end{satz} +% +% Info über die Beta-Verteilung +% +\input{chapters/040-rekursion/betaverteilung.tex} + +\subsection{Weitere Eigenschaften der Gamma-Funktion} +Die nahe Verwandtschaft der Gamma- mit der Beta-Funktion ermöglicht +nun, weitere Eigenschaften der Gamma-Funktion mit Hilfe der Beta-Funktion +herzuleiten. + \subsubsection{Nochmals der Wert von $\Gamma(\frac12)$?} Der Wert von $\Gamma(\frac12)=\sqrt{\pi}$ wurde bereits in \eqref{buch:rekursion:gamma:wert12} @@ -484,83 +500,3 @@ Setzt man $x=\frac12$ in die Verdoppelungsformel ein, erhält man in Übereinstimmung mit dem aus \eqref{buch:rekursion:gamma:gamma12} bereits bekannten Wert. -\subsubsection{Beta-Funktion und Binomialkoeffizienten} -Die Binomialkoeffizienten können mit Hilfe der Fakultät als -\begin{align*} -\binom{n}{k} -&= -\frac{n!}{(n-k)!\,k!} -\intertext{geschrieben werden. -Drückt man die Fakultäten durch die Gamma-Funktion aus, erhält man} -&= -\frac{\Gamma(n+1)}{\Gamma(n-k+1)\Gamma(k+1)}. -\intertext{Schreibt man $x=k-1$ und $y=n-k+1$, wird daraus -wegen $x+y=k+1+n-k+1=n+2=(n+1)+1$} -&= -\frac{\Gamma(x+y-1)}{\Gamma(x)\Gamma(y)}. -\intertext{Die Rekursionsformel für die Gamma-Funktion erlaubt, -den Zähler umzuwandeln in $\Gamma(x+y-1)=\Gamma(x+y)/(x+y-1)$, so dass -der Binomialkoeffizient schliesslich} -&= -\frac{\Gamma(x+y)}{(x+y-1)\Gamma(x)\Gamma(y)} -= -\frac{1}{(n-1)B(n-k+1,k+1)} -\label{buch:rekursion:gamma:binombeta} -\end{align*} -geschrieben werden kann. -Die Rekursionsbeziehung -\[ -\binom{n+1}{k} = \binom{n}{k-1} + \binom{n}{k} -\] -der Binomialkoeffizienten erzeugt das vertraute Pascal-Dreieck, -die Formel \eqref{buch:rekursion:gamma:binombeta} für die -Binomialkoeffizienten macht daraus -\[ -\frac{n-1}{B(n-k,k-1)} -= -\frac{n-2}{B(n-k,k-2)} -+ -\frac{n-2}{B(n-k-1,k-1)}, -\] -die für ganzzahlige Argumente gilt. -Wir wollen nachrechnen, dass dies für beliebige Argumente gilt. -\begin{align*} -\frac{(n-1)\Gamma(n-1)}{\Gamma(n-k)\Gamma(k-1)} -&= -\frac{(n-2)\Gamma(n-2)}{\Gamma(n-k)\Gamma(k-2)} -+ -\frac{(n-2)\Gamma(n-2)}{\Gamma(n-k-1)\Gamma(k-1)} -\\ -\frac{\Gamma(n)}{\Gamma(n-k)\Gamma(k-1)} -&= -\frac{\Gamma(n-1)}{\Gamma(n-k)\Gamma(k-2)} -+ -\frac{\Gamma(n-1)}{\Gamma(n-k-1)\Gamma(k-1)} -\intertext{Durch Zusammenfassen der Faktoren im Zähler mit Hilfe -der Rekursionsformel für die Gamma-Funktion und Multiplizieren -mit dem gemeinsamen Nenner -$\Gamma(n-k)\Gamma(k-1)=(n-k-1)\Gamma(n-k-1)(k-2)\Gamma(k-2)$ wird daraus} -\Gamma(n) -&= -(k-2) -\Gamma(n-1) -+ -(n-k-1) -\Gamma(n-1) -\intertext{Indem wir die Rekursionsformel für die Gamma-Funktion auf -die rechte Seite anwenden können wir erreichen, dass in allen Termen -ein Faktor -$\Gamma(n-1)$ auftritt:} -(n-1)\Gamma(n-1) -&= -(k-2)\Gamma(n-1) -+ -(n+k-1)\Gamma(n-1) -\\ -n-1 -&= -k-2 -+ -n-k-1 -\end{align*} - diff --git a/buch/chapters/040-rekursion/images/Makefile b/buch/chapters/040-rekursion/images/Makefile index 9608a94..86dfa1e 100644 --- a/buch/chapters/040-rekursion/images/Makefile +++ b/buch/chapters/040-rekursion/images/Makefile @@ -3,7 +3,7 @@ # # (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule # -all: gammaplot.pdf fibonacci.pdf +all: gammaplot.pdf fibonacci.pdf order.pdf beta.pdf gammaplot.pdf: gammaplot.tex gammapaths.tex pdflatex gammaplot.tex @@ -16,3 +16,17 @@ fibonaccigrid.tex: fibonacci.m fibonacci.pdf: fibonacci.tex fibonaccigrid.tex pdflatex fibonacci.tex + +order.pdf: order.tex orderpath.tex + pdflatex order.tex + +orderpath.tex: order.m + octave order.m + +beta.pdf: beta.tex betapaths.tex + pdflatex beta.tex + +betapaths.tex: betadist.m + octave betadist.m + + diff --git a/buch/chapters/040-rekursion/images/beta.pdf b/buch/chapters/040-rekursion/images/beta.pdf new file mode 100644 index 0000000..0e6567b Binary files /dev/null and b/buch/chapters/040-rekursion/images/beta.pdf differ diff --git a/buch/chapters/040-rekursion/images/beta.tex b/buch/chapters/040-rekursion/images/beta.tex new file mode 100644 index 0000000..1e1a1b3 --- /dev/null +++ b/buch/chapters/040-rekursion/images/beta.tex @@ -0,0 +1,236 @@ +% +% beta.tex -- display some symmetric beta distributions +% +% (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,calc} +\input{betapaths.tex} +\begin{document} +\def\skala{12} +\definecolor{colorone}{rgb}{1.0,0.6,0.0} +\definecolor{colortwo}{rgb}{1.0,0.0,0.0} +\definecolor{colorthree}{rgb}{0.6,0.0,0.6} +\definecolor{colorfour}{rgb}{0.6,0.0,1.0} +\definecolor{colorfive}{rgb}{0.0,0.0,1.0} +\definecolor{colorsix}{rgb}{0.4,0.6,1.0} +\definecolor{colorseven}{rgb}{0.0,0.0,0.0} +\definecolor{coloreight}{rgb}{0.0,0.8,0.8} +\definecolor{colornine}{rgb}{0.0,0.8,0.2} +\definecolor{colorten}{rgb}{0.2,0.4,0.0} +\definecolor{coloreleven}{rgb}{0.6,1.0,0.0} +\definecolor{colortwelve}{rgb}{1.0,0.8,0.4} + +\def\achsen{ + \foreach \x in {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9}{ + \draw ({\x*\dx},{-0.1/\skala}) -- ({\x*\dx},{0.1/\skala}); + \node at ({\x*\dx},{-0.1/\skala}) [below] {$\x$}; + } + \foreach \y in {1,2,3,4}{ + \draw ({-0.1/\skala},{\y*\dy}) -- ({0.1/\skala},{\y*\dy}); + \node at ({-0.1/\skala},{\y*\dy}) [left] {$\y$}; + } + \def\x{1} + \draw ({\x*\dx},{-0.1/\skala}) -- ({\x*\dx},{0.1/\skala}); + \node at ({\x*\dx},{-0.1/\skala}) [below] {$\x$}; + \def\x{0} + \node at ({\x*\dx},{-0.1/\skala}) [below] {$\x$}; + + \draw[->] ({-0.1/\skala},0) -- ({1*\dx+0.4/\skala},0) + coordinate[label={$x$}]; + \draw[->] (0,{-0.1/\skala}) -- (0,{\betamax*\dy+0.4/\skala},0) + coordinate[label={right:$\beta(a,b,x)$}]; +} + +\def\farbcoord#1#2{ + ({\dx*(0.63+((#1)/5)*0.27)},{\dx*(0.18+((#2)/5)*0.27)}) +} +\def\farbviereck{ + \foreach \x in {1,2,3,4}{ + \draw[color=gray!30] \farbcoord{\x}{0} -- \farbcoord{\x}{4}; + \draw[color=gray!30] \farbcoord{0}{\x} -- \farbcoord{4}{\x}; + } + \draw[->] \farbcoord{0}{0} -- \farbcoord{4.4}{0} + coordinate[label={$a$}]; + \draw[->] \farbcoord{0}{0} -- \farbcoord{0}{4.4} + coordinate[label={left: $b$}]; + \foreach \x in {1,2,3,4}{ + \node[color=gray] at \farbcoord{4}{\x} [right] {\tiny $b=\x$}; + %\fill[color=white,opacity=0.7] + % \farbcoord{(\x-0.1)}{3.3} + % rectangle + % \farbcoord{(\x+0.1)}{4}; + \node[color=gray] at \farbcoord{\x}{4} [right,rotate=90] + {\tiny $a=\x$}; + } +} +\def\farbpunkt#1#2#3{ + \fill[color=#3] \farbcoord{#1}{#2} circle[radius={0.1/\skala}]; +} + +\begin{tikzpicture}[>=latex,thick,scale=\skala] + +\def\dx{1.15} +\def\dy{0.1} +\def\opa{0.1} + +\def\betamax{4.9} + +\begin{scope} +\clip (0,0) rectangle ({1*\dx},{\betamax*\dy}); +\fill[color=colorone,opacity=\opa] (0,0) -- \betaaa -- (\dx,0) -- cycle; +\fill[color=colortwo,opacity=\opa] (0,0) -- \betabb -- (\dx,0) -- cycle; +\fill[color=colorthree,opacity=\opa] (0,0) -- \betacc -- (\dx,0) -- cycle; +\fill[color=colorfour,opacity=\opa] (0,0) -- \betadd -- (\dx,0) -- cycle; +\fill[color=colorfive,opacity=\opa] (0,0) -- \betaee -- (\dx,0) -- cycle; +\fill[color=colorsix,opacity=\opa] (0,0) -- \betaff -- (\dx,0) -- cycle; +\fill[color=colorseven,opacity=\opa] (0,0) -- \betagg -- (\dx,0) -- cycle; +\fill[color=coloreight,opacity=\opa] (0,0) -- \betahh -- (\dx,0) -- cycle; +\fill[color=colornine,opacity=\opa] (0,0) -- \betaii -- (\dx,0) -- cycle; +\fill[color=colorten,opacity=\opa] (0,0) -- \betajj -- (\dx,0) -- cycle; +\fill[color=coloreleven,opacity=\opa] (0,0) -- \betakk -- (\dx,0) -- cycle; +\fill[color=colortwelve,opacity=\opa] (0,0) -- \betall -- (\dx,0) -- cycle; + +\draw[color=colorone] \betaaa; +\draw[color=colortwo] \betabb; +\draw[color=colorthree] \betacc; +\draw[color=colorfour] \betadd; +\draw[color=colorfive] \betaee; +\draw[color=colorsix] \betaff; +\draw[color=colorseven] \betagg; +\draw[color=coloreight] \betahh; +\draw[color=colornine] \betaii; +\draw[color=colorten] \betajj; +\draw[color=coloreleven] \betakk; +\draw[color=colortwelve] \betall; + +\end{scope} + +\achsen + +\farbviereck + +\farbpunkt{\alphatwelve}{\betatwelve}{colortwelve} +\farbpunkt{\alphaeleven}{\betaeleven}{coloreleven} +\farbpunkt{\alphaten}{\betaten}{colorten} +\farbpunkt{\alphanine}{\betanine}{colornine} +\farbpunkt{\alphaeight}{\betaeight}{coloreight} +\farbpunkt{\alphaseven}{\betaseven}{colorseven} +\farbpunkt{\alphasix}{\betasix}{colorsix} +\farbpunkt{\alphafive}{\betafive}{colorfive} +\farbpunkt{\alphafour}{\betafour}{colorfour} +\farbpunkt{\alphathree}{\betathree}{colorthree} +\farbpunkt{\alphatwo}{\betatwo}{colortwo} +\farbpunkt{\alphaone}{\betaone}{colorone} + + +\def\betamax{4.9} + +\begin{scope}[yshift=-0.6cm] + +\begin{scope} +\clip (0,0) rectangle ({1*\dx},{\betamax*\dy}); +\fill[color=colorone,opacity=\opa] (0,0) -- \betaea -- (\dx,0) -- cycle; +\fill[color=colortwo,opacity=\opa] (0,0) -- \betaeb -- (\dx,0) -- cycle; +\fill[color=colorthree,opacity=\opa] (0,0) -- \betaec -- (\dx,0) -- cycle; +\fill[color=colorfour,opacity=\opa] (0,0) -- \betaed -- (\dx,0) -- cycle; +\fill[color=colorfive,opacity=\opa] (0,0) -- \betaee -- (\dx,0) -- cycle; +\fill[color=colorsix,opacity=\opa] (0,0) -- \betaef -- (\dx,0) -- cycle; +\fill[color=colorseven,opacity=\opa] (0,0) -- \betaeg -- (\dx,0) -- cycle; +\fill[color=coloreight,opacity=\opa] (0,0) -- \betaeh -- (\dx,0) -- cycle; +\fill[color=colornine,opacity=\opa] (0,0) -- \betaei -- (\dx,0) -- cycle; +\fill[color=colorten,opacity=\opa] (0,0) -- \betaej -- (\dx,0) -- cycle; +\fill[color=coloreleven,opacity=\opa] (0,0) -- \betaek -- (\dx,0) -- cycle; +\fill[color=colortwelve,opacity=\opa] (0,0) -- \betael -- (\dx,0) -- cycle; + +\draw[color=colorone] \betaea; +\draw[color=colortwo] \betaeb; +\draw[color=colorthree] \betaec; +\draw[color=colorfour] \betaed; +\draw[color=colorfive] \betaee; +\draw[color=colorsix] \betaef; +\draw[color=colorseven] \betaeg; +\draw[color=coloreight] \betaeh; +\draw[color=colornine] \betaei; +\draw[color=colorten] \betaej; +\draw[color=coloreleven] \betaek; +\draw[color=colortwelve] \betael; +\end{scope} + +\achsen + +\farbviereck + +\farbpunkt{\alphafive}{\betatwelve}{colortwelve} +\farbpunkt{\alphafive}{\betaeleven}{coloreleven} +\farbpunkt{\alphafive}{\betaten}{colorten} +\farbpunkt{\alphafive}{\betanine}{colornine} +\farbpunkt{\alphafive}{\betaeight}{coloreight} +\farbpunkt{\alphafive}{\betaseven}{colorseven} +\farbpunkt{\alphafive}{\betasix}{colorsix} +\farbpunkt{\alphafive}{\betafive}{colorfive} +\farbpunkt{\alphafive}{\betafour}{colorfour} +\farbpunkt{\alphafive}{\betathree}{colorthree} +\farbpunkt{\alphafive}{\betatwo}{colortwo} +\farbpunkt{\alphafive}{\betaone}{colorone} + +\end{scope} + +\begin{scope}[yshift=-1.2cm] + +\begin{scope} +\clip (0,0) rectangle ({1*\dx},{\betamax*\dy}); +\fill[color=colorone,opacity=\opa] (0,0) -- \betaal -- (\dx,0) -- cycle; +\fill[color=colortwo,opacity=\opa] (0,0) -- \betabl -- (\dx,0) -- cycle; +\fill[color=colorthree,opacity=\opa] (0,0) -- \betacl -- (\dx,0) -- cycle; +\fill[color=colorfour,opacity=\opa] (0,0) -- \betadl -- (\dx,0) -- cycle; +\fill[color=colorfive,opacity=\opa] (0,0) -- \betael -- (\dx,0) -- cycle; +\fill[color=colorsix,opacity=\opa] (0,0) -- \betafl -- (\dx,0) -- cycle; +\fill[color=colorseven,opacity=\opa] (0,0) -- \betagl -- (\dx,0) -- cycle; +\fill[color=coloreight,opacity=\opa] (0,0) -- \betahl -- (\dx,0) -- cycle; +\fill[color=colornine,opacity=\opa] (0,0) -- \betail -- (\dx,0) -- cycle; +\fill[color=colorten,opacity=\opa] (0,0) -- \betajl -- (\dx,0) -- cycle; +\fill[color=coloreleven,opacity=\opa] (0,0) -- \betakl -- (\dx,0) -- cycle; +\fill[color=colortwelve,opacity=\opa] (0,0) -- \betall -- (\dx,0) -- cycle; + +\draw[color=colorone] \betaal; +\draw[color=colortwo] \betabl; +\draw[color=colorthree] \betacl; +\draw[color=colorfour] \betadl; +\draw[color=colorfive] \betael; +\draw[color=colorsix] \betafl; +\draw[color=colorseven] \betagl; +\draw[color=coloreight] \betahl; +\draw[color=colornine] \betail; +\draw[color=colorten] \betajl; +\draw[color=coloreleven] \betakl; +\draw[color=colortwelve] \betall; +\end{scope} + +\achsen + +\farbviereck + +\farbpunkt{\alphatwelve}{\betatwelve}{colortwelve} +\farbpunkt{\alphaeleven}{\betatwelve}{coloreleven} +\farbpunkt{\alphaten}{\betatwelve}{colorten} +\farbpunkt{\alphanine}{\betatwelve}{colornine} +\farbpunkt{\alphaeight}{\betatwelve}{coloreight} +\farbpunkt{\alphaseven}{\betatwelve}{colorseven} +\farbpunkt{\alphasix}{\betatwelve}{colorsix} +\farbpunkt{\alphafive}{\betatwelve}{colorfive} +\farbpunkt{\alphafour}{\betatwelve}{colorfour} +\farbpunkt{\alphathree}{\betatwelve}{colorthree} +\farbpunkt{\alphatwo}{\betatwelve}{colortwo} +\farbpunkt{\alphaone}{\betatwelve}{colorone} + +\end{scope} + +\end{tikzpicture} +\end{document} + diff --git a/buch/chapters/040-rekursion/images/betadist.m b/buch/chapters/040-rekursion/images/betadist.m new file mode 100644 index 0000000..5b466a6 --- /dev/null +++ b/buch/chapters/040-rekursion/images/betadist.m @@ -0,0 +1,58 @@ +# +# betadist.m +# +# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule +# +global N; +N = 201; +global nmin; +global nmax; +nmin = -4; +nmax = 7; +n = nmax - nmin + 1 +A = 3; + +t = (nmin:nmax) / nmax; +alpha = 1 + A * t .* abs(t) +#alpha(1) = 0.01; + +#alpha = [ 1, 1.03, 1.05, 1.1, 1.25, 1.5, 2, 2.5, 3, 4, 5 ]; +beta = alpha; +names = [ "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; + "nine"; "ten"; "eleven"; "twelve" ] + +function retval = Beta(a, b, x) + retval = x^(a-1) * (1-x)^(b-1) / beta(a, b); + if (retval > 100) + retval = 100 + end +end + +function plotbeta(fn, a, b, name) + global N; + fprintf(fn, "\\def\\beta%s{\n", strtrim(name)); + fprintf(fn, "\t({%.4f*\\dx},{%.4f*\\dy})", 0, Beta(a, b, 0)); + for x = (1:N-1)/(N-1) + X = (1-cos(pi * x))/2; + fprintf(fn, "\n\t--({%.4f*\\dx},{%.4f*\\dy})", + X, Beta(a, b, X)); + end + fprintf(fn, "\n}\n"); +end + +fn = fopen("betapaths.tex", "w"); + +for i = (1:n) + fprintf(fn, "\\def\\alpha%s{%f}\n", strtrim(names(i,:)), alpha(i)); + fprintf(fn, "\\def\\beta%s{%f}\n", strtrim(names(i,:)), beta(i)); +end + +for i = (1:n) + for j = (1:n) + printf("working on %d,%d:\n", i, j); + plotbeta(fn, alpha(i), beta(j), + char(['a' + i - 1, 'a' + j - 1])); + end +end + +fclose(fn); diff --git a/buch/chapters/040-rekursion/images/order.m b/buch/chapters/040-rekursion/images/order.m new file mode 100644 index 0000000..762f458 --- /dev/null +++ b/buch/chapters/040-rekursion/images/order.m @@ -0,0 +1,119 @@ +# +# order.m +# +# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule +# +global N; +N = 10; +global subdivisions; +subdivisions = 100; +global P; +P = 0.5 + +function retval = orderF(p, n, k) + retval = 0; + for i = (k:n) + retval = retval + nchoosek(n,i) * p^i * (1-p)^(n-i); + end +end + +function retval = orderd(p, n, k) + retval = 0; + for i = (k:n) + s = i * p^(i-1) * (1-p)^(n-i); + s = s - p^i * (n-i) * (1-p)^(n-i-1); + retval = retval + nchoosek(n,i) * s; + end +end + +function retval = orders(p, n, k) + retval = k * nchoosek(n, k) * p^(k-1) * (1-p)^(n-k); +end + +function orderpath(fn, k, name) + fprintf(fn, "\\def\\order%s{\n\t(0,0)", name); + global N; + global subdivisions; + for i = (0:subdivisions) + p = i/subdivisions; + fprintf(fn, "\n\t-- ({%.4f*\\dx},{%.4f*\\dy})", + p, orderF(p, N, k)); + end + fprintf(fn, "\n}\n"); +end + +function orderdpath(fn, k, name) + fprintf(fn, "\\def\\orderd%s{\n\t(0,0)", name); + global N; + global subdivisions; + for i = (1:subdivisions-1) + p = i/subdivisions; + fprintf(fn, "\n\t-- ({%.4f*\\dx},{%.4f*\\dy})", + p, orderd(p, N, k)); + end + fprintf(fn, "\n\t-- ({1*\\dx},0)"); + fprintf(fn, "\n}\n"); +end + +function orderspath(fn, k, name) + fprintf(fn, "\\def\\orders%s{\n\t(0,0)", name); + global N; + global subdivisions; + for i = (1:subdivisions-1) + p = i/subdivisions; + fprintf(fn, "\n\t-- ({%.4f*\\dx},{%.4f*\\dy})", + p, orders(p, N, k)); + end + fprintf(fn, "\n\t-- ({1*\\dx},0)"); + fprintf(fn, "\n}\n"); +end + +fn = fopen("orderpath.tex", "w"); + +orderpath(fn, 0, "zero"); +orderdpath(fn, 0, "zero"); +orderspath(fn, 0, "zero"); + +orderpath(fn, 1, "one"); +orderdpath(fn, 1, "one"); +orderspath(fn, 1, "one"); + +orderpath(fn, 2, "two"); +orderdpath(fn, 2, "two"); +orderspath(fn, 2, "two"); + +orderpath(fn, 3, "three"); +orderdpath(fn, 3, "three"); +orderspath(fn, 3, "three"); + +orderpath(fn, 4, "four"); +orderdpath(fn, 4, "four"); +orderspath(fn, 4, "four"); + +orderpath(fn, 5, "five"); +orderdpath(fn, 5, "five"); +orderspath(fn, 5, "five"); + +orderpath(fn, 6, "six"); +orderdpath(fn, 6, "six"); +orderspath(fn, 6, "six"); + +orderpath(fn, 7, "seven"); +orderdpath(fn, 7, "seven"); +orderspath(fn, 7, "seven"); + +orderpath(fn, 8, "eight"); +orderdpath(fn, 8, "eight"); +orderspath(fn, 8, "eight"); + +orderpath(fn, 9, "nine"); +orderdpath(fn, 9, "nine"); +orderspath(fn, 9, "nine"); + +orderpath(fn, 10, "ten"); +orderdpath(fn, 10, "ten"); +orderspath(fn, 10, "ten"); + +fclose(fn); + + diff --git a/buch/chapters/040-rekursion/images/order.pdf b/buch/chapters/040-rekursion/images/order.pdf new file mode 100644 index 0000000..cc175a9 Binary files /dev/null and b/buch/chapters/040-rekursion/images/order.pdf differ diff --git a/buch/chapters/040-rekursion/images/order.tex b/buch/chapters/040-rekursion/images/order.tex new file mode 100644 index 0000000..9a2511c --- /dev/null +++ b/buch/chapters/040-rekursion/images/order.tex @@ -0,0 +1,125 @@ +% +% order.tex -- Verteilungsfunktion für Ordnungsstatistik +% +% (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{8} +\definecolor{darkgreen}{rgb}{0,0.6,0} + +\def\n{10} +\def\E#1#2{ + \draw[color=#2] + ({\dx*#1/(\n+1)},{-0.1/\skala}) -- ({\dx*#1/(\n+1)},{4.4*\dy}); + \node[color=#2] at ({\dx*#1/(\n+1)},{3.2*\dy}) + [rotate=90,above right] {$k=#1$}; +} +\def\var#1#2{ + \pgfmathparse{\dx*sqrt(#1*(\n-#1+1)/((\n+1)*(\n+1)*(\n+2)))} + \xdef\var{\pgfmathresult} + \fill[color=#2,opacity=0.5] + ({\dx*#1/(\n+1)-\var},0) rectangle ({\dx*#1/(\n+1)+\var},{4.4*\dy}); +} + +\input{orderpath.tex} +\begin{tikzpicture}[>=latex,thick,scale=\skala] + +\def\dx{1.6} +\def\dy{0.5} + +\def\pfad#1#2{ +\draw[color=#2,line width=1.4pt] ({-0.1/\skala},0) + -- + #1 + -- + ({1*\dx+0.1/\skala},0.5); +} + +\pfad{\orderzero}{darkgreen!20} +\pfad{\orderone}{darkgreen!20} +\pfad{\ordertwo}{darkgreen!20} +\pfad{\orderthree}{darkgreen!20} +\pfad{\orderfour}{darkgreen!20} +\pfad{\orderfive}{darkgreen!20} +\pfad{\ordersix}{darkgreen!20} +\pfad{\ordereight}{darkgreen!20} +\pfad{\ordernine}{darkgreen!20} +\pfad{\orderten}{darkgreen!20} +\pfad{\orderseven}{darkgreen} + +\draw[->] ({-0.1/\skala},0) -- ({1.03*\dx},0) coordinate[label={$x$}]; +\draw[->] (0,{-0.1/\skala}) -- (0,0.6) coordinate[label={right:$F(X)$}]; +\foreach \x in {0,0.2,0.4,0.6,0.8,1}{ + \draw ({\x*\dx},{-0.1/\skala}) -- ({\x*\dx},{0.1/\skala}); + \node at ({\x*\dx},{-0.1/\skala}) [below] {$\x$}; +} +\foreach \y in {0.5,1}{ + \draw ({-0.1/\skala},{\y*\dy}) -- ({0.1/\skala},{\y*\dy}); + \node at ({-0.1/\skala},{\y*\dy}) [left] {$\y$}; +} + +\node[color=darkgreen] at (0.65,{0.5*\dy}) [above,rotate=55] {$k=7$}; + +\begin{scope}[yshift=-0.7cm] +\def\dy{0.125} + +\foreach \k in {1,2,3,4,5,6,8,9,10}{ + \E{\k}{blue!30} +} +\def\k{7} +\var{\k}{orange!40} +\node[color=blue] at ({\dx*\k/(\n+1)},{4.3*\dy}) [above] {$E(X_{7:n})$}; + +\def\pfad#1#2{ + \draw[color=#2,line width=1.4pt] ({-0.1/\skala},0) + -- + #1 + -- + ({1*\dx+0.1/\skala},0.0); +} + +\begin{scope} +\clip ({-0.1/\skala},{-0.1/\skala}) + rectangle ({1*\dx+0.1/\skala},{0.56+0.1/\skala}); + +\pfad{\orderdzero}{red!20} +\pfad{\orderdone}{red!20} +\pfad{\orderdtwo}{red!20} +\pfad{\orderdthree}{red!20} +\pfad{\orderdfour}{red!20} +\pfad{\orderdfive}{red!20} +\pfad{\orderdsix}{red!20} +\pfad{\orderdeight}{red!20} +\pfad{\orderdnine}{red!20} +\pfad{\orderdten}{red!20} +\E{\k}{blue} +\pfad{\orderdseven}{red} + +\end{scope} + +\draw[->] ({-0.1/\skala},0) -- ({1.03*\dx},0) coordinate[label={$x$}]; +\draw[->] (0,{-0.1/\skala}) -- (0,0.6) coordinate[label={right:$\varphi(X)$}]; +\foreach \x in {0,0.2,0.4,0.6,0.8,1}{ + \draw ({\x*\dx},{-0.1/\skala}) -- ({\x*\dx},{0.1/\skala}); + \node at ({\x*\dx},{-0.1/\skala}) [below] {$\x$}; +} +\foreach \y in {1,2,3,4}{ + \draw ({-0.1/\skala},{\y*\dy}) -- ({0.1/\skala},{\y*\dy}); + \node at ({-0.1/\skala},{\y*\dy}) [left] {$\y$}; +} + +\node[color=red] at ({0.67*\dx},{2.7*\dy}) [above] {$k=7$}; + + +\end{scope} + +\end{tikzpicture} +\end{document} + -- cgit v1.2.1