Changed colors for listings. Small improvements on the script.
This commit is contained in:
parent
dbe0a2173c
commit
3ca3c7b499
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -62,7 +62,7 @@ sigma = 2.3;
|
||||
y = randn(100, 1)*sigma + mu;
|
||||
\end{lstlisting}
|
||||
|
||||
Das ist manchmal auch sinnvoll f\"ur \code{zeros} oder \code{ones}:
|
||||
Das gleiche Prinzip ist manchmal auch sinnvoll f\"ur \code{zeros} oder \code{ones}:
|
||||
\begin{lstlisting}
|
||||
x = -1:0.01:2; % Vektor mit x-Werten
|
||||
plot(x, exp(-x.*x));
|
||||
@ -75,11 +75,14 @@ plot(x, ones(size(x))*0.5);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\section{for Schleifen \"uber Vektoren}
|
||||
Manchmal m\"ochte man doch mit einer for-Schleife \"uber einen Vektor iterieren:
|
||||
Manchmal m\"ochte man doch mit einer for-Schleife \"uber einen Vektor iterieren.
|
||||
\begin{lstlisting}
|
||||
x = [2:3:20]; % irgendein Vektor
|
||||
for i=1:length(x)
|
||||
% Benutze den Wert des Vektors x an der Stelle des Indexes i:
|
||||
for i=1:length(x) % Mit der for-Schleife "loopen" wir ueber den Vektor
|
||||
i % das ist der Index der die Elemente des Vektors nacheinander indiziert.
|
||||
x(i) % das ist der Wert des i-ten Elements des Vektors x.
|
||||
a = x(i); % die Variable a bekommt den Wert des i-ten Elements des Vektors x zugewiesen.
|
||||
% Benutze den Wert:
|
||||
do_something( x(i) );
|
||||
end
|
||||
\end{lstlisting}
|
||||
@ -89,7 +92,7 @@ sollten wir uns vor der Schleife schon einen Vektor f\"ur die Ergebnisse
|
||||
erstellen:
|
||||
\begin{lstlisting}
|
||||
x = [2:3:20]; % irgendein Vektor
|
||||
y = zeros(size(x)); % Platz fuer die Ergebnisse
|
||||
y = zeros(length(x),1); % Platz fuer die Ergebnisse, genauso viele wie Loops der Schleife
|
||||
for i=1:length(x)
|
||||
% Schreibe den Rueckgabewert der Funktion get_something an die i-te
|
||||
% Stelle von y:
|
||||
@ -125,7 +128,8 @@ for i=1:length(x)
|
||||
% Die Funktion get_something gibt uns einen Vektor zurueck:
|
||||
z = get_something( x(i) );
|
||||
% dessen Inhalt h\"angen wir an unseren Ergebnissvektor an:
|
||||
y = [y z(:)];
|
||||
y = [y; z(:)];
|
||||
% z(:) stellt sicher, das wir auf jeden Fall einen Spaltenvektoren aneinanderreihen.
|
||||
end
|
||||
% jetzt koennen wir dem Ergebnisvektor weiter bearbeiten:
|
||||
mean(y)
|
||||
|
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -2,8 +2,9 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# roll the die:
|
||||
x1 = np.random.random_integers( 1, 6, 100 )
|
||||
x2 = np.random.random_integers( 1, 6, 500 )
|
||||
rng = np.random.RandomState(57281)
|
||||
x1 = rng.random_integers( 1, 6, 100 )
|
||||
x2 = rng.random_integers( 1, 6, 500 )
|
||||
bins = np.arange(0.5, 7, 1.0)
|
||||
|
||||
plt.xkcd()
|
||||
@ -14,7 +15,10 @@ ax.spines['right'].set_visible(False)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.yaxis.set_ticks_position('left')
|
||||
ax.xaxis.set_ticks_position('bottom')
|
||||
ax.set_xlim(0, 7)
|
||||
ax.set_xticks( range(1, 7) )
|
||||
ax.set_xlabel( 'x' )
|
||||
ax.set_ylim(0, 98)
|
||||
ax.set_ylabel( 'Frequency' )
|
||||
ax.hist([x2, x1], bins, color=['#FFCC00', '#FFFF66' ])
|
||||
|
||||
@ -23,9 +27,13 @@ ax.spines['right'].set_visible(False)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.yaxis.set_ticks_position('left')
|
||||
ax.xaxis.set_ticks_position('bottom')
|
||||
ax.set_xlim(0, 7)
|
||||
ax.set_xticks( range(1, 7) )
|
||||
ax.set_xlabel( 'x' )
|
||||
ax.set_ylim(0, 0.23)
|
||||
ax.set_ylabel( 'Probability' )
|
||||
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ])
|
||||
ax.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], '-r', lw=2, zorder=1)
|
||||
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ], zorder=10)
|
||||
plt.tight_layout()
|
||||
fig.savefig( 'diehistograms.pdf' )
|
||||
#plt.show()
|
||||
|
@ -2,9 +2,10 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# normal distribution:
|
||||
rng = np.random.RandomState(6281)
|
||||
x = np.arange( -4.0, 4.0, 0.01 )
|
||||
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
||||
r = np.random.randn( 100 )
|
||||
r = rng.randn( 100 )
|
||||
|
||||
plt.xkcd()
|
||||
|
||||
@ -15,9 +16,10 @@ ax.spines['top'].set_visible(False)
|
||||
ax.yaxis.set_ticks_position('left')
|
||||
ax.xaxis.set_ticks_position('bottom')
|
||||
ax.set_xlabel( 'x' )
|
||||
ax.set_xlim(-3.2, 3.2)
|
||||
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
|
||||
ax.set_ylabel( 'Frequency' )
|
||||
#ax.set_ylim( 0.0, 0.46 )
|
||||
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
|
||||
ax.set_yticks( np.arange( 0.0, 41.0, 10.0 ) )
|
||||
ax.hist(r, 5, color='#CC0000')
|
||||
ax.hist(r, 20, color='#FFCC00')
|
||||
|
||||
@ -27,11 +29,14 @@ ax.spines['top'].set_visible(False)
|
||||
ax.yaxis.set_ticks_position('left')
|
||||
ax.xaxis.set_ticks_position('bottom')
|
||||
ax.set_xlabel( 'x' )
|
||||
ax.set_xlim(-3.2, 3.2)
|
||||
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
|
||||
ax.set_ylabel( 'Probability density p(x)' )
|
||||
#ax.set_ylim( 0.0, 0.46 )
|
||||
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
|
||||
ax.hist(r, 5, normed=True, color='#CC0000')
|
||||
ax.hist(r, 20, normed=True, color='#FFCC00')
|
||||
ax.set_ylim(0.0, 0.44)
|
||||
ax.set_yticks( np.arange( 0.0, 0.41, 0.1 ) )
|
||||
ax.plot(x, g, '-b', lw=2, zorder=-1)
|
||||
ax.hist(r, 5, normed=True, color='#CC0000', zorder=-10)
|
||||
ax.hist(r, 20, normed=True, color='#FFCC00', zorder=-5)
|
||||
|
||||
plt.tight_layout()
|
||||
fig.savefig( 'pdfhistogram.pdf' )
|
||||
|
@ -163,9 +163,9 @@
|
||||
numbers=left,
|
||||
showstringspaces=false,
|
||||
language=Matlab,
|
||||
commentstyle=\itshape\color{darkgray},
|
||||
keywordstyle=\color{blue},
|
||||
stringstyle=\color{green},
|
||||
commentstyle=\itshape\color{red!60!black},
|
||||
keywordstyle=\color{blue!50!black},
|
||||
stringstyle=\color{green!50!black},
|
||||
backgroundcolor=\color{blue!10},
|
||||
breaklines=true,
|
||||
breakautoindent=true,
|
||||
|
@ -111,7 +111,8 @@ Wahrscheinlichkeitsverteilung der Messwerte ab.
|
||||
to their sum.}{Histogramme des Ergebnisses von 100 oder 500 mal
|
||||
W\"urfeln. Links: das absolute Histogramm z\"ahlt die Anzahl des
|
||||
Auftretens jeder Augenzahl. Rechts: Normiert auf die Summe des
|
||||
Histogramms werden die beiden Messungen vergleichbar.}}
|
||||
Histogramms werden die beiden Messungen untereinander als auch
|
||||
mit der theoretischen Verteilung $P=1/6$ vergleichbar.}}
|
||||
\end{figure}
|
||||
|
||||
Bei ganzzahligen Messdaten (z.B. die Augenzahl eines W\"urfels)
|
||||
@ -142,7 +143,9 @@ Meistens haben wir es jedoch mit reellen Messgr\"o{\ss}en zu tun.
|
||||
normalverteilten Messwerten. Links: Die H\"ohe des absoluten
|
||||
Histogramms h\"angt von der Klassenbreite ab. Rechts: Bei auf
|
||||
das Integral normierten Histogrammen werden auch
|
||||
unterschiedliche Klassenbreiten vergleichbar.}}
|
||||
unterschiedliche Klassenbreiten untereinander vergleichbar und
|
||||
auch mit der theoretischen Wahrschinlichkeitsdichtefunktion
|
||||
(blau).}}
|
||||
\end{figure}
|
||||
|
||||
Histogramme von reellen Messwerten m\"ussen auf das Integral 1
|
||||
|
Reference in New Issue
Block a user