matrices almost done

This commit is contained in:
Jan Grewe 2015-11-03 18:29:19 +01:00
parent 84c950c246
commit 240303051f
7 changed files with 164 additions and 16 deletions

View File

@ -1,7 +1,7 @@
%!PS-Adobe-2.0 EPSF-2.0 %!PS-Adobe-2.0 EPSF-2.0
%%Title: pointprocessscetchA.tex %%Title: pointprocessscetchA.tex
%%Creator: gnuplot 4.6 patchlevel 4 %%Creator: gnuplot 4.6 patchlevel 4
%%CreationDate: Mon Nov 2 19:55:25 2015 %%CreationDate: Tue Nov 3 17:29:16 2015
%%DocumentFonts: %%DocumentFonts:
%%BoundingBox: 50 50 373 135 %%BoundingBox: 50 50 373 135
%%EndComments %%EndComments
@ -430,10 +430,10 @@ SDict begin [
/Title (pointprocessscetchA.tex) /Title (pointprocessscetchA.tex)
/Subject (gnuplot plot) /Subject (gnuplot plot)
/Creator (gnuplot 4.6 patchlevel 4) /Creator (gnuplot 4.6 patchlevel 4)
/Author (jan) /Author (grewe)
% /Producer (gnuplot) % /Producer (gnuplot)
% /Keywords () % /Keywords ()
/CreationDate (Mon Nov 2 19:55:25 2015) /CreationDate (Tue Nov 3 17:29:16 2015)
/DOCINFO pdfmark /DOCINFO pdfmark
end end
} ifelse } ifelse

View File

@ -1,7 +1,7 @@
%!PS-Adobe-2.0 EPSF-2.0 %!PS-Adobe-2.0 EPSF-2.0
%%Title: pointprocessscetchB.tex %%Title: pointprocessscetchB.tex
%%Creator: gnuplot 4.6 patchlevel 4 %%Creator: gnuplot 4.6 patchlevel 4
%%CreationDate: Mon Nov 2 19:57:38 2015 %%CreationDate: Tue Nov 3 18:24:39 2015
%%DocumentFonts: %%DocumentFonts:
%%BoundingBox: 50 50 373 237 %%BoundingBox: 50 50 373 237
%%EndComments %%EndComments
@ -430,10 +430,10 @@ SDict begin [
/Title (pointprocessscetchB.tex) /Title (pointprocessscetchB.tex)
/Subject (gnuplot plot) /Subject (gnuplot plot)
/Creator (gnuplot 4.6 patchlevel 4) /Creator (gnuplot 4.6 patchlevel 4)
/Author (jan) /Author (grewe)
% /Producer (gnuplot) % /Producer (gnuplot)
% /Keywords () % /Keywords ()
/CreationDate (Mon Nov 2 19:57:38 2015) /CreationDate (Tue Nov 3 18:24:39 2015)
/DOCINFO pdfmark /DOCINFO pdfmark
end end
} ifelse } ifelse

View File

@ -432,33 +432,181 @@ Dimensions of matrices being concatenated are not consistent.
\subsection{Matrizen} \subsection{Matrizen}
Im Gegesatz zu den 1-dimensionalen Vektoren k\"onnen Martizen
n-dimensional sein, das hei{\ss}t, dass sie beliebig viele Dimensionen
haben k\"onnen. Von praktischer Bedeutung sind allerdings nur Matrizen
mit bis zu vier Dimensionen. Meist beschr\"ankt es sich jedoch auf 2-
bis 3-d Matrizen (Abbildung \ref{matrixfig} A,B).
\begin{figure} \begin{figure}
\includegraphics[width=0.5\columnwidth]{matrices} \includegraphics[width=0.5\columnwidth]{matrices}
\caption{\textbf{Indices von Vektoren.} Jedes Feld eines Vektors hat \caption{\textbf{Matrizen. A)} Eine Variable (``test'') die eine
einen Index mit dem auf den jeweiligen Inhalt zugegriffen werden 2-dimensionale Matrize ist. \textbf{B)} Illustration einer
kann.}\label{vectorindexingfig} 3-dimensionalen Matrize. Die Pfeile zeigen den Rang der
Dimensionen an.}\label{matrixfig}
\end{figure} \end{figure}
Erzeugt werden Matrizen sehr \"ahnlich zu den Vektoren (Listing
\ref{matrixListing}). Die Definition einer Matrize wird, wie beim
Vektor, durch \code{[]} eingeschlossen. Das \code{;} trennt die
einzelnen Zeilen der Matrize.
\footnotesize
\begin{lstlisting}[label=matrixListing, caption={Erzeugen von Matrizen.}]
>> a = [1 2 3; 4 5 6; 7 8 9]
>> a =
1 2 3
4 5 6
7 8 9
>>
>> b = ones(3,3,2);
>> b
b(:,:,1) =
1 1 1
1 1 1
1 1 1
b(:,:,2) =
1 1 1
1 1 1
1 1 1
\end{lstlisting}
\normalsize
Zur Defintion von mehr-dimensionalen Matrizen ist die Notation in
Zeile 1 nicht wirklich geeignet. Es gibt allerdings eine Reihe von
Helferfunktionen, die n-dimensionale Matrizen erstellen k\"onnen
(z.B. \code{ones}, Zeile 7). Sollte sich die Notwendigkeit ergeben
mehrdimensionale Matrizen zusammenzuf\"ugen hilft die \code{cat}
Funktion.
Um Informationen \"uber die Gr\"{\ss}e einer Matrize zu bekommen ist
die Funktion \code{length} nicht geeignet. Wie oben erw\"ahnt gibt sie
die Gr\"o{\ss}e der l\"angsten Dimension aus. Wann immer es um
Matrizen geht, wird \code{size} benutzt.
\begin{figure} \begin{figure}
\includegraphics[width=0.9\columnwidth]{matrixIndexing} \includegraphics[width=0.9\columnwidth]{matrixIndexing}
\caption{\textbf{Indices von Vektoren.} Jedes Feld eines Vektors hat \caption{\textbf{Indices von Matrizen.} Jedes Feld einer Matrize
einen Index mit dem auf den jeweiligen Inhalt zugegriffen werden wird durch einen Index individuell angesprochen. Der Index setzt
kann.}\label{vectorindexingfig} sich aus so vielen Zahlen zusammen wie es Dimensionen gibt (links
2, rechts 3). Dabei steht die 1. Stelle immer f\"ur die Zeile, die
2. f\"uer die Spalte und die dritte f\"ur das Blatt,
etc.. }\label{matrixindexingfig}
\end{figure} \end{figure}
Der Zugriff auf Inhalte von Matrizen erfolgt \"uber den Index
(Abbildung \ref{matrixindexingfig}, Listing
\ref{matrixIndexing}). \"Ahnlich zu den Positionen in einem
Koordinatensystem wird jede Zelle einer Matrize mit einem Index
angesprochen, der aus $n$ Zahlen besteht wobei $n$ die
Dimensionalit\"at der Matrize ist. Diese Art des Zugriffs wird
\textit{subsript indexing} genannt.
\footnotesize
\begin{lstlisting}[caption={Zugriff auf Inhalte von Matrizen,
Indexierung.}, label=matrixIndexing]
>> x = randi(100, [3, 4, 5]); % 3-D Matrix mit Zufallszahlen
>> size(x)
ans =
3 4 5
>> x(1,1,1); % obere linke Ecke
ans(1,1,1) =
14
>>
>> x(1,1,:) % obere linke Ecke entlang der 3. Dimension
ans(1,1,:) =
14
ans(:,:,2) =
58
ans(:,:,3) =
4
ans(:,:,4) =
93
ans(:,:,5) =
56
\end{lstlisting}
\normalsize
Alternativ zum \textit{subscript indexing} k\"onnen die Zellen einer
Matrize auch \textit{linear} angesprochen werden (Abbildung
\ref{matrixlinearindexingfig}). Diese Art der Adressierung ist nicht
so intuituiv verst\"andlich, kann aber sehr hilfreich sein. Der
``linare'' Index einer Zelle reicht von 1 bis \code{numel(M)}
Elemente. Wobei dieser erst entlang der 1. Dimension, dann der 2.,
3. etc. Dimension ansteigt. Listing \ref{matrixLinearIndexing} zeigt
ein Beispiel fuer den Einsatz des linearen Indexierens z.B. wenn man
den Minimalwert aller Elemente einer Matrize ermitteln m\"ochte..
\begin{figure} \begin{figure}
\includegraphics[width=0.9\columnwidth]{matrixLinearIndexing} \includegraphics[width=0.9\columnwidth]{matrixLinearIndexing}
\caption{\textbf{Indices von Vektoren.} Jedes Feld eines Vektors hat \caption{\textbf{Lineares Indexieren von Matrizen.} Der Index steigt
einen Index mit dem auf den jeweiligen Inhalt zugegriffen werden linear von 1 bis zur Anzahl Elemente in der Matrize an. Dabei
kann.}\label{vectorindexingfig} steigt der Index zuerst entlang der ersten, zweiten, dritten und
weiterer Dimensionen an.}\label{matrixlinearindexingfig}
\end{figure} \end{figure}
\begin{lstlisting}[label=matrixLinearIndexing, caption={Lineares Indexieren in Matrizen.}]
>> x = randi(100, [3, 4, 5]); % 3-D Matrix mit Zufallszahlen
>> size(x)
ans =
3 4 5
>> numel(x)
ans =
60
>> min(min(min(x))) % Minumum uber die Zeilen, Spalten, Blaetter...
ans =
4
>> min(x(:)) % oder so
ans =
4
\end{lstlisting}
Beim Rechnen mit Matrizen gelten die gleichen Regeln wie bei
Vektoren. Matrizen k\"onnen solange elementweise miteinander
Verrechnet werden, wie die Dimensionalit\"aten
\"ubereinstimmen. Besondere Vorsicht sollte man immer dann walten
lassen, wenn man Matrizen miteinander mulitplizieren, dividieren oder
postenzieren will. Hier ist es wichtig sich klarzumachen was man will:
Eine elementweise multiplikation (\code{.*} Operator, Listing
\ref{matrixOperations} Zeile 18) oder ob eine Matrixmultiplikation
(\code{*} Operator, Listing \ref{matrixOperations} Zeile 12)
durchgef\"uhrt werden soll.
\footnotesize
\begin{lstlisting}[label=matrixOperations, caption={Zwei Arten von Multiplikationen auf Matrizen.}]
>> A = randi(10, [3, 3]) % 2-D Matrix
A =
3 8 2
2 10 3
10 7 1
>> B = randi(10, [3, 3]) % dto
B =
2 1 7
1 5 9
5 10 5
>>
>> A * B % Matrix Multiplikation
ans =
24 63 103
29 82 119
32 55 138
>>
>> A .* B % Elementweise Multiplikation
ans =
6 8 14
2 50 27
50 70 5
>>
\end{lstlisting}
\normalsize
\section{Boolesche Operationen} \section{Boolesche Operationen}
\section{Logisches Indizieren} \section{Logisches Indizieren}

View File

@ -413,7 +413,7 @@
\framesubtitle{Indexierung} \framesubtitle{Indexierung}
\tiny \tiny
\begin{lstlisting} \begin{lstlisting}
>> x = roundi(100, [3, 4, 5]); % 3-D Matrix mit Zufallszahlen >> x = randi(100, [3, 4, 5]); % 3-D Matrix mit Zufallszahlen
>> >>
>> x(1,1,1); % obere linke Ecke >> x(1,1,1); % obere linke Ecke
ans(1,1,1) = ans(1,1,1) =

Binary file not shown.