---
fontsize: 8pt
format:
  beamer:
    include-in-header: ../ALM_Header.tex
bibliography: ../ALM_Referenzen.bib
---


# {.plain}
<!-- Vorlesungstitel -->
\center
```{r, echo = F, out.width = "20%"}
knitr::include_graphics("../OvGU_Logo.png")
```

\vspace{2mm}
\huge
Allgemeines Lineares Modell

\vspace{6mm}
\large
BSc Psychologie, SoSe 2026

\vspace{5mm}
Joram Soch


<!-- Sitzung 3: Matrizen -->
# {.plain}

\vfill
\center
\huge
\textcolor{black}{(3) Matrizen}
\vfill


<!-- Motivation -->
#

\large
\textcolor{darkblue}{Motivation}

\setstretch{2}
\normalsize
Matrizen sind die Worte der Sprache der Datenanalyse.

Vektoren sind nur spezielle Matrizen. (Skalare sind nur spezielle Vektoren.)

Matrizen können als Tabellen der Datenrepräsentation dienen.

Matrizen können lineare Abbildungen repräsentieren.

Matrizen können Vektorräume repräsentieren.

\vspace{6mm}

\center
\setstretch{1.2}
\textcolor{darkblue}{$\Rightarrow$ Ein sicherer Umgang mit Matrizen ist für das Verständnis}

\textcolor{darkblue}{moderner datenanalytischer Verfahren unverzichtbar.}


<!-- Inhaltsverzeichnis -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

Inverse

Determinanten

Rang und Spur

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Abschnitt 1: Definition -->
#

\large
\setstretch{2}
\vfill

**Definition**

Operationen

Inverse

Determinanten

Rang und Spur

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Definition: Matrix -->
# Definition

\small
\begin{definition}[Matrix]

\justifying
Eine Matrix ist eine rechteckige Anordnung von Zahlen, die wie folgt bezeichnet wird:
\begin{equation}
A := \begin{pmatrix*}[r]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}
:= {(a_{ij})}_{1\le i\le n,\, 1\le j\le m}.
\end{equation}

\end{definition}

\footnotesize
Bemerkungen

* Matrizen bestehen aus *Zeilen (rows)* und *Spalten (columns)*.
* Die Matrixeinträge $a_{ij}$ werden mit einem *Zeilenindex* $i$ und einem *Spaltenindex* $j$ indiziert.
\vspace{2mm}

* Zum Beispiel gilt für
$A:=\begin{pmatrix*}[r]
2 & 7 & 5 & 2 \\
8 & 3 & 5 & 6 \\
6 & 4 & 0 & 9 \\
9 & 2 & 1 & 2
\end{pmatrix*}$,
dass
$a_{32} = 4$.


<!-- Bemerkungen -->
# Definition

\setstretch{2}
\small
Bemerkungen (fortgeführt)

\footnotesize
* Die *Größe* oder *Dimension* einer Matrix ergibt sich aus der Anzahl ihrer Zeilen $n \in \mathbb{N}$ und Spalten $m \in \mathbb{N}$.
* Matrizen mit $n = m$ heißen *quadratische Matrizen*.
* In der Folge benötigen wir nur Matrizen mit reellen Einträgen, also $a_{ij} \in \mathbb{R}$ für alle $i = 1,...,n, j = 1,...,m$.
* Wir nennen die Matrizen mit reellen Einträge *reelle Matrizen*.
* Die Menge der reellen Matrizen mit $n$ Zeilen und $m$ Spalten bezeichnen wir mit $\mathbb{R}^{n \times m}$.
* Aus dem Ausdruck $A \in \mathbb{R}^{2 \times 3}$ lesen wir ab, dass $A$ eine reelle Matrix mit zwei Zeilen und drei Spalten ist.
* Wir identifizieren die Menge $\mathbb{R}^{1 \times 1}$ mit der Menge $\mathbb{R}$.
* Wir identifizieren die Menge $\mathbb{R}^{n \times 1}$ mit der Menge $\mathbb{R}^n$.
* Reelle Matrizen mit einer Spalte und $n$ Zeilen sind also dasselbe wie $n$-dimensionale reelle Vektoren.


<!-- Abschnitt 2: Operationen -->
#

\large
\setstretch{2}
\vfill

Definition

**Operationen**

Inverse

Determinanten

Rang und Spur

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Übersicht -->
# Operationen

\textcolor{darkblue}{Matrixoperationen}
\setstretch{2}

\small
Man kann mit Matrizen rechnen.

In der Folge betrachten wir folgende grundlegende Matrixoperationen:

* Addition und Subtraktion von Matrizen gleicher Größe (Matrixaddition und Matrixsubtraktion)
* Multiplikation einer Matrix mit einem Skalar (Skalarmultiplikation)
* Vertauschen der Zeilen- und Spaltenanordnung (Matrixtransposition)
* Multiplikation einer Matrix mit einer passenden zweiten Matrix (Matrixmultiplikation)
* "Division" durch eine quadratische Matrix (Matrixinversion)


<!-- Definition: Matrixaddition -->
# Operationen

\footnotesize
\begin{definition}[Matrixaddition]

\justifying
Es seien $A,B\in \mathbb{R}^{n\times m}$. Dann ist  die \textit{Addition} von $A$ und $B$ definiert als die Abbildung
\begin{equation}
+ : \mathbb{R}^{n\times m} \times \mathbb{R}^{n\times m} \to \mathbb{R}^{n \times m}, \,
(A,B) \mapsto +(A,B) := A + B
\end{equation}

mit
\begin{align}
\begin{split}
A + B
& =
\begin{pmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}
+
\begin{pmatrix*}[c]
b_{11} & b_{12} & \cdots & b_{1m} \\
b_{21} & b_{22} & \cdots & b_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
b_{n1} & b_{n2} & \cdots & b_{nm}
\end{pmatrix*} \\
& :=
\begin{pmatrix*}[c]
a_{11} + b_{11} & a_{12} + b_{12} & \cdots & a_{1m} + b_{1m} \\
a_{21} + b_{21} & a_{22} + b_{22} & \cdots & a_{2m} + b_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} + b_{n1} & a_{n2} + b_{n2} & \cdots & a_{nm} + b_{nm}
\end{pmatrix*}.
\end{split}
\end{align}

\end{definition}

Bemerkungen

* Nur Matrizen identischer Größe können miteinander addiert werden.
* Die Addition zweier gleich großer Matrizen ist *elementweise* definiert.


<!-- Definition: Matrixsubtraktion -->
# Operationen

\footnotesize
\begin{definition}[Matrixsubtraktion]

\justifying
Es seien $A,B\in \mathbb{R}^{n\times m}$. Dann ist die \textit{Subtraktion} von $A$
und $B$ definiert als die Abbildung
\begin{equation}
- : \mathbb{R}^{n\times m} \times \mathbb{R}^{n\times m} \to \mathbb{R}^{n\times m}, \,
(A,B) \mapsto -(A,B) := A - B
\end{equation}

mit
\begin{align}
\begin{split}
A - B
& =
\begin{pmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}
-
\begin{pmatrix*}[c]
b_{11} & b_{12} & \cdots & b_{1m} \\
b_{21} & b_{22} & \cdots & b_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
b_{n1} & b_{n2} & \cdots & b_{nm}
\end{pmatrix*} \\
& :=
\begin{pmatrix*}[c]
a_{11} - b_{11} & a_{12} - b_{12} & \cdots & a_{1m} - b_{1m} \\
a_{21} - b_{21} & a_{22} - b_{22} & \cdots & a_{2m} - b_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} - b_{n1} & a_{n2} - b_{n2} & \cdots & a_{nm} - b_{nm}
\end{pmatrix*}.
\end{split}
\end{align}

\end{definition}

Bemerkungen

* Nur Matrizen identischer Größe können voneinander subtrahiert werden.
* Die Subktration zweier gleich großer Matrizen ist *elementweise* definiert.


<!-- Beispiel -->
# Operationen

\small
Beispiel

\footnotesize
Es seien $A,B\in \mathbb{R}^{2\times 3}$ definiert als
\begin{equation}
A:=\begin{pmatrix*}[r]
2 & -3 & 0 \\
1 &  6 & 5 \\
\end{pmatrix*}
\quad \mbox{und} \quad
B := \begin{pmatrix*}[r]
 4 & 1 & 0 \\
-4 & 2 & 0 \\
\end{pmatrix*}.
\end{equation}

Da $A$ und $B$ gleich groß sind, können wir sie addieren
\begin{align}
\begin{split}
C:= A+B
& =
\begin{pmatrix*}[r]
2 & -3 & 0 \\
1 &  6 & 5 \\
\end{pmatrix*}
+
\begin{pmatrix*}[r]
 4 & 1 & 0 \\
-4 & 2 & 0 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
2 + 4 & -3 + 1 & 0 + 0 \\
1 - 4 &  6 + 2 & 5 + 0 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
 6 & -2 & 0 \\
-3 &  8 & 5 \\
\end{pmatrix*}
\end{split}
\end{align}

und voneinander subtrahieren
\begin{align}
\begin{split}
D:= A-B
& =
\begin{pmatrix*}[r]
2 & -3 & 0 \\
1 &  6 & 5 \\
\end{pmatrix*}
-
\begin{pmatrix*}[r]
 4 & 1 & 0 \\
-4 & 2 & 0 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
2 - 4 & -3 - 1 & 0 - 0 \\
1 + 4 &  6 - 2 & 5 - 0 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
-2 & -4 & 0 \\
5 &  4 & 5  \\
\end{pmatrix*}.
\end{split}
\end{align}


<!-- Beispiel in R -->
# Operationen

\small
Beispiel

\vspace{5mm}
\footnotesize

```{r, echo = T}
# spaltenweise Definition von A (R-Default)
A = matrix(c(2,1,-3,6,0,5), nrow = 2)
print(A)
```

\vspace{5mm}

```{r, echo = T}
# zeilenweise Definition von B
B = matrix(c(4,1,0,-4,2,0), nrow = 2, byrow = TRUE)
print(B)
```


<!-- Beispiel in R -->
# Operationen

\small
Beispiel

\vspace{5mm}
\footnotesize

```{r, echo = T}
# Addition
C = A + B
print(C)
```

\vspace{5mm}

```{r, echo = T}
# Subtraktion
D = A - B
print(D)
```


<!-- Definition: Skalarmultiplikation -->
# Operationen

\footnotesize
\begin{definition}[Skalarmultiplikation]

\justifying
Es sei $c \in \mathbb{R}$ ein Skalar und $A \in \mathbb{R}^{n\times m}$. Dann
ist die \textit{Skalarmultiplikation} von $c$ und $A$ definiert als die Abbildung
\begin{equation}
\cdot : \mathbb{R} \times \mathbb{R}^{n\times m} \to \mathbb{R}^{n\times m}, \,
(c,A) \mapsto \cdot (c,A) := cA
\end{equation}

mit
\begin{align}
\begin{split}
cA
= c
\begin{pmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}
:=
\begin{pmatrix*}[c]
ca_{11} & ca_{12} & \cdots & ca_{1m} \\
ca_{21} & ca_{22} & \cdots & ca_{2m} \\
\vdots  & \vdots  & \ddots & \vdots  \\
ca_{n1} & ca_{n2} & \cdots & ca_{nm}
\end{pmatrix*}.
\end{split}
\end{align}

\end{definition}

Bemerkungen

* Die Skalarmultiplikation ist *elementweise* definiert.


<!-- Beispiel -->
# Operationen

\small
Beispiel

\footnotesize
Es seien $c:=-3$ und $A\in \mathbb{R}^{4\times 3}$ definiert als
\begin{equation}
A := \begin{pmatrix*}[r]
3 & 1 & 1 \\
5 & 2 & 5 \\
2 & 7 & 1 \\
3 & 4 & 2
\end{pmatrix*}.
\end{equation}

Dann ergibt sich
\begin{align}
\begin{split}
B := cA
= -3
\begin{pmatrix*}[r]
3 & 1 & 1 \\
5 & 2 & 5 \\
2 & 7 & 1 \\
3 & 4 & 2
\end{pmatrix*}
= \begin{pmatrix*}[r]
-3\cdot3 & -3\cdot1 & -3\cdot1 \\
-3\cdot5 & -3\cdot2 & -3\cdot5 \\
-3\cdot2 & -3\cdot7 & -3\cdot1 \\
-3\cdot3 & -3\cdot4 & -3\cdot2
\end{pmatrix*}
=
\begin{pmatrix*}[r]
-9  &  -3 & -3  \\
-15 &  -6 & -15 \\
-6  & -21 & -3  \\
-9  & -12 & -6
\end{pmatrix*}.
\end{split}
\end{align}


<!-- Beispiel in R -->
# Operationen

\small
Beispiel

\vspace{5mm}
\footnotesize

```{r, echo = T}
# Definitionen
c = -3                    # Skalar c
A = matrix(c(3,1,1,       # Matrix A
             5,2,5,
             2,7,1,
             3,4,2),
           nrow  = 4,     # Anzahl Zeilen
           byrow = TRUE)  # zeilenweise

# Skalarmultiplikation
B = c*A
print(B)
```


<!-- Theorem: Vektorram R^{n x m} -->
# Operationen

\footnotesize
\begin{theorem}[Vektorraum $\mathbb{R}^{n \times m}$]

\justifying
\normalfont
Das Tripel $(\mathbb{R}^{n \times m}, +, \cdot)$ mit der oben definierten Matrixaddition und Skalarmultiplikation ist ein Vektorraum. Insbesondere gelten also für $A,B,C\in \mathbb{R}^{n \times m}$ und $r,s,t\in \mathbb{R}$ folgende Rechenregeln:

\vspace{2mm}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{ll}
(1) Kommutativität der Addition
& $A + B = B + A$ \\
(2) Assoziativität der Addition
& $(A + B) + C = A + (B + C)$ \\
(3) Existenz eines neutralen Elements der Addition
& $\exists\, 0 \in \mathbb{R}^{n \times m}$ mit $A + 0 = 0 + A = A$ \\
(4) Existenz inverser Elemente der Addition
& $\forall A \, \exists\, -A $ mit  $A + (-A) = 0$ \\
(5) Existenz eines neutralen Elements der Skalarmultiplikation
& $\exists\, 1 \in \mathbb{R}$ mit $1 \cdot A = A$ \\
(6) Assoziativität der Skalarmultiplikation
& $r \cdot (s \cdot t) = (r \cdot s)\cdot t$ \\
(7) Distributivität hinsichtlich der Matrixaddition
& $r\cdot (A + B) = r\cdot A + r\cdot B$ \\
(8) Distributivität hinsichtlich der Skalaraddition
& $(r + s)\cdot A = r\cdot A + s\cdot A$
\end{tabular}

\end{theorem}

Bemerkungen

* Wir verzichten auf einen Beweis.
* Der Beweis ergibt sich mit dem elementweisen Charakter von $+,-,\cdot$ und den Rechenregeln in $(\mathbb{R},+,\cdot)$.
* Das neutrale Element der Addition heißt *Nullmatrix*; wir schreiben $0_{nm} := (0)_{1\le i \le n, 1 \le j \le m}$ mit $0\in \mathbb{R}$.
* Die inversen Elemente der Addition sind durch $-A := (-a_{ij})_{1\le i \le n, 1 \le j \le m}$ gegeben.
* Das neutrale Element der Skalarmultiplikation ist $1 \in \mathbb{R}$.


<!-- Definition: Matrixtransposition -->
# Operationen

\footnotesize
\begin{definition}[Matrixtransposition]

\justifying
Es sei $A \in \mathbb{R}^{n\times m}$. Dann ist  die \textit{Transposition} von $A$ definiert als die Abbildung
\begin{equation}
\cdot^{\mathrm{T}} : \mathbb{R}^{n\times m} \to \mathbb{R}^{m \times n}, \,
A \mapsto \cdot^{\mathrm{T}}(A) := A^\mathrm{T}
\end{equation}

mit
\begin{align}
\begin{split}
A^\mathrm{T}
=
\begin{pmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}^\mathrm{T}
:=
\begin{pmatrix*}[c]
a_{11} & a_{21} & \cdots & a_{n1} \\
a_{12} & a_{22} & \cdots & a_{n2} \\
\vdots & \vdots & \ddots & \vdots \\
a_{1m} & a_{2m} & \cdots & a_{nm}
\end{pmatrix*}
\end{split}
\end{align}

\end{definition}

Bemerkungen

* Die Matrixtransposition "vertauscht" Zeilen und Spalten.
* Das Transponieren einer Matrix wird auch als *Stürzen einer Matrix* bezeichnet ([\textcolor{darkblue}{Animation}](https://upload.wikimedia.org/wikipedia/commons/e/e4/Matrix_transpose.gif)).
* Für $A \in \mathbb{R}^{n \times m}$ gilt immer $A^\mathrm{T} \in \mathbb{R}^{m \times n}$.
* Für $A \in \mathbb{R}^{1 \times 1}$ gilt immer $A^\mathrm{T} = A$.
* Es gilt $\left(A^\mathrm{T}\right)^\mathrm{T} = A$.
* Es gilt $\left(a_{ii}\right)_{1 \le i \le \mbox{min}(n,m)} = \left(a_{ii}\right)^\mathrm{T}_{1 \le i \le \mbox{min}(n,m)}$.
* Matrixelemente auf der Hauptdiagonalen einer Matrix bleiben bei Transposition also unberührt.


<!-- Beispiel -->
# Operationen

\small
Beispiel

Es sei $A \in \mathbb{R}^{2 \times 3}$ definiert durch
\begin{equation}
A :=
\begin{pmatrix*}[r]
2 & 3 & 0 \\
1 & 6 & 5 \\
\end{pmatrix*} \; .
\end{equation}

Dann gilt $A^\mathrm{T} \in \mathbb{R}^{3 \times 2}$ und speziell
\begin{equation}
A^\mathrm{T} =
\begin{pmatrix*}[r]
2  & 1 \\
3  & 6 \\
0  & 5 \\
\end{pmatrix*} \; .
\end{equation}

Weiterhin gilt offenbar $\min(m,n) = 2$ und folglich
\begin{equation}
(a_{11}) = \left(a_{11}\right)^\mathrm{T}
\mbox{ und }
(a_{22}) = \left(a_{22}\right)^\mathrm{T} \; .
\end{equation}


<!-- Beispiel in R -->
# Operationen

\small
Beispiel

\vspace{5mm}
\footnotesize

```{r, echo = T}
# Definition
A = matrix(c(2,3,0,
             1,6,5),
           nrow  = 2,
           byrow = TRUE)
print(A)
```

\vspace{5mm}

\footnotesize
```{r, echo = T}
# Transposition
AT = t(A)
print(AT)
```


<!-- Definition: Matrixmultiplikation -->
# Operationen

\footnotesize
\setstretch{1.5}
\begin{definition}[Matrixmultiplikation]

\justifying
Es seien $A\in \mathbb{R}^{n \times m}$ und $B \in \mathbb{R}^{m \times k}$. Dann ist die \textit{Matrixmultiplikation} von $A$ und $B$ definiert als die Abbildung
\begin{equation}
\cdot : \mathbb{R}^{n\times m} \times \mathbb{R}^{m\times k} \to \mathbb{R}^{n \times k}, \,
(A,B) \mapsto \cdot(A,B) := AB
\end{equation}

mit
\begin{align}
\begin{split}
AB
& =
\begin{pmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{pmatrix*}
\begin{pmatrix*}[c]
b_{11} & b_{12} & \cdots & b_{1k} \\
b_{21} & b_{22} & \cdots & b_{2k} \\
\vdots & \vdots & \ddots & \vdots \\
b_{m1} & b_{m2} & \cdots & b_{mk}
\end{pmatrix*} \\
& :=
\begin{pmatrix*}[c]
\sum_{i=1}^m a_{1i}b_{i1} & \sum_{i=1}^m a_{1i}b_{i2} & \cdots & \sum_{i=1}^m a_{1i}b_{ik}  \\
\sum_{i=1}^m a_{2i}b_{i1} & \sum_{i=1}^m a_{2i}b_{i2} & \cdots & \sum_{i=1}^m a_{2i}b_{ik}  \\
\vdots                    & \vdots                    & \ddots & \vdots                     \\
\sum_{i=1}^m a_{ni}b_{i1} & \sum_{i=1}^m a_{ni}b_{i2} & \cdots & \sum_{i=1}^m a_{ni}b_{ik}
\end{pmatrix*} \\
& =
\left(\sum_{i=1}^m a_{ji}b_{il} \right)_{1 \le j \le n, 1 \le l \le k}
\end{split}
\end{align}

\end{definition}


<!-- Bemerkungen -->
# Operationen

\small
Bemerkungen

\setstretch{1.5}
\begin{itemize}
\justifying

\item Das Matrixprodukt $AB$ ist nur dann definiert, wenn $A$ genau so viele Spalten hat wie $B$ Zeilen.

\item Informell gilt für die beteiligten Matrixgrößen immer $(n \times m)(m \times k) = (n \times k)$.

\item In $AB$ ist $(AB)_{ij}$ die Summe der multiplizierten $i$ten Zeilen von $A$ und $j$ten Spalten von $B$.

\item Zum Berechnen von $(AB)_{ij}$ für $1 \le i \le n, 1 \le j \le k$ geht man also wie folgt vor:

\begin{enumerate}
\begin{small}
\justifying
\item Man legt in Gedanken die Tranposition der $i$ten Zeile von $A$ über die $j$te Spalte von $B$.
\item Weil $A$ genau $m$ Spalten hat und $B$ genau $m$ Zeilen hat, gibt es zu jedem Element der Zeile aus $A$ ein korrespondierendes Element in der Spalte von $B$.
\item Man multipliziert die korrespondierenden Elemente miteinander.
\item Man summiert die Ergebnisse auf.
\item Dies ist der Eintrag mit Index $ij$ in $AB$.
\end{small}
\end{enumerate}

\item Die Multiplikation von Matrizen ist im Allgemeinen nicht kommutativ (also meist $AB \neq BA$).

\end{itemize}


<!-- Visualisierung der Matrixmultiplikation -->
# Operationen

Visualisierung der Matrixmultiplikation
\vspace{2mm}

```{r, echo = F, out.width = "60%", fig.align = "center"}
knitr::include_graphics("Abbildungen/matrix_multiplication.png")
```

\vspace{2mm}
\center
\footnotesize
(Quelle: [*Wikimedia Commons*: "Matrix_multiplication_diagram_2.svg"](https://en.m.wikipedia.org/wiki/File:Matrix_multiplication_diagram_2.svg); Lizenz: GNU Free, CC-BY-SA 3.0.)


<!-- Beispiel -->
# Operationen

Beispiel

\small
\justifying
$A \in \mathbb{R}^{2 \times 3}$ und $B \in \mathbb{R}^{3 \times 2}$ seien definiert als
\begin{equation}
A := \begin{pmatrix*}[r]
2 & -3 &  0 \\
1 &  6 &  5
\end{pmatrix*}
\quad \mbox{und} \quad
B := \begin{pmatrix*}[r]
 4 & 2 \\
-1 & 0 \\
 1 & 3
\end{pmatrix*}.
\end{equation}
Wir wollen $C := AB$ und $D := BA$ berechnen.

Mit $n = 2, m = 3$ und $k = 2$ wissen wir schon, dass $C \in \mathbb{R}^{2 \times 2}$ und $D \in \mathbb{R}^{3 \times 3}$, weil
\begin{equation}
(2 \times 3)(3 \times 2) = (2 \times 2)
\end{equation}
und
\begin{equation}
(3 \times 2)(2 \times 3) = (3 \times 3)
\end{equation}

Es gilt hier also sicher $AB \neq BA$.


<!-- Beispiel -->
# Operationen

Beispiel (fortgeführt)

\small
\justifying
Es ergibt sich zum einen
\begin{align}
\begin{split}
C
& =
AB \\
& = \begin{pmatrix*}[r]
2 & -3 & 0 \\
1 &  6 & 5 \\
\end{pmatrix*}
\begin{pmatrix*}[r]
4  & 2 \\
-1 & 0 \\
1  & 3
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
2\cdot 4 + (-3)\cdot (-1) + 0\cdot 1 & 2\cdot 2 + (-3)\cdot 0 + 0\cdot 3 \\
1\cdot 4 +    6\cdot (-1) + 5\cdot 1 & 1\cdot 2 +    6\cdot 0 + 5\cdot 3 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
8 + 3 + 0 & 4 + 0 + 0  \\
4 - 6 + 5 & 2 + 0 + 15 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
11 & 4 \\
3 & 17 \\
\end{pmatrix*}.
\end{split}
\end{align}


<!-- Beispiel in R -->
# Operationen

Beispiel (fortgeführt)

\vspace{2mm}
\footnotesize

```{r, echo = T}
# Definitionen
A = matrix(c( 2,-3, 0,
              1, 6, 5),
           nrow  = 2,
           byrow = TRUE)
B = matrix(c( 4, 2,
             -1, 0,
              1, 3),
           nrow  = 3,
           byrow = TRUE)

# Matrixmultiplikation
C = A %*% B                     # (2 x 3)(3 x 2) = (2 x 2)
print(C)
```


<!-- Beispiel -->
# Operationen

Beispiel (fortgeführt)

\small
\justifying
Es ergibt sich zum anderen
\begin{align}
\begin{split}
D
& =
BA \\
& =
\begin{pmatrix*}[r]
4  & 2 \\
-1 & 0 \\
1  & 3
\end{pmatrix*}
\begin{pmatrix*}[r]
2 & -3 & 0 \\
1 &  6 & 5 \\
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
  4    \cdot   2  + 2 \cdot 1
& 4    \cdot (-3) + 2 \cdot 6
& 4    \cdot   0  + 2 \cdot 5 \\
  (-1) \cdot  2  + 0 \cdot 1
& (-1) \cdot(-3) + 0 \cdot 6
& (-1) \cdot  0  + 0 \cdot 5 \\
  1    \cdot  2  + 3 \cdot 1
& 1    \cdot(-3) + 3 \cdot 6
& 1    \cdot  0  + 3 \cdot 5
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
    8 + 2
& -12 + 12
&   0 + 5  \\
   -2 + 0
&   3 + 0
&   0 + 0  \\
    2 + 3
&  -3 + 18
&   0 + 15
\end{pmatrix*} \\
& =
\begin{pmatrix*}[r]
  10
&  0
& 10 \\
  -2
&  3
&  0 \\
   5
& 15
& 15 \\
\end{pmatrix*}.
\end{split}
\end{align}


<!-- Beispiel in R -->
# Operationen

Beispiel (fortgeführt)

\vspace{1mm}
\footnotesize

```{r, echo = T}
# Definitionen
A = matrix(c( 2,-3, 0,
              1, 6, 5),
           nrow  = 2,
           byrow = TRUE)
B = matrix(c( 4, 2,
             -1, 0,
              1, 3),
           nrow  = 3,
           byrow = TRUE)

# Matrixmultiplikation
D = B %*% A                     # (3 x 2)(2 x 3) = (3 x 3)
print(D)
```


<!-- Beispiel in R -->
# Operationen

Beispiel (fortgeführt)

\vspace{1mm}
\footnotesize

```{r, echo = T, error = T}
# Definitionen
A = matrix(c( 2,-3, 0,
              1, 6, 5),
           nrow  = 2,
           byrow = TRUE)
B = matrix(c( 4, 2,
             -1, 0,
              1, 3),
           nrow  = 3,
           byrow = TRUE)

# Beispiel für eine nicht-definierte Matrixmultiplikation
E = t(A) %*% B                  # (3 x 2)(3 x 2)
```


<!-- Theorem: Skalarprodukt als Matrixmultiplikation -->
# Operationen

\footnotesize
\begin{theorem}[Skalarprodukt als Matrixmultiplikation]

\normalfont
\justifying
Es seien $x,y \in \mathbb{R}^n$ zwei $n$-dimensionale Vektoren und
\begin{equation}
\langle x,y \rangle := \sum_{i=1}^n x_i y_i
\end{equation}

sei ihr Skalarprodukt. Dann gilt
\begin{equation}
\langle x,y \rangle = x^\mathrm{T} y.
\end{equation}

\end{theorem}

\footnotesize
Bemerkungen

* Das Skalarprodukt bildet zwei gleich große Vektoren auf eine Zahl ab.
* Das Skalarprodukt zweier Vektoren kann als Matrixprodukt geschrieben werden.

\vspace{2mm}
\underline{Beweis}
\vspace{-2mm}

\begin{equation}
x^\mathrm{T} y
=
\begin{pmatrix*}
x_1    \\
x_2    \\
\vdots \\
x_n
\end{pmatrix*}^\mathrm{T}
\begin{pmatrix*}
y_1    \\
y_2    \\
\vdots \\
y_n
\end{pmatrix*}
=
\begin{pmatrix*}
x_1 & x_2 & \ldots & x_n
\end{pmatrix*}
\begin{pmatrix*}
y_1    \\
y_2    \\
\vdots \\
y_n
\end{pmatrix*}
=
x_1 y_1 + x_2 y_2 + \ldots + x_n y_n
=
\sum_{i=1}^n x_i y_i
=
\langle x,y \rangle
\end{equation}
$\hfill\Box$


<!-- Theorem: Matrixmultiplikation und Skalarprodukt -->
# Operationen

\footnotesize
\begin{theorem}[Matrixmultiplikation und Skalarprodukt]

\normalfont
\justifying
Gegeben seien zwei Matrizen $A \in \mathbb{R}^{m \times n}$ und $B \in \mathbb{R}^{n \times k}$.

Die Spalten von $A^\mathrm{T}$ für $i = 1,...,m$ seien bezeichnet durch
\begin{equation}
\bar{a}_i := (a_{ji})_{1 \le j \le n} \in \mathbb{R}^n
\end{equation}

und die Spalten von $B$ für $i = 1,...,k$ seien bezeichnet durch
\begin{equation}
\bar{b}_j := (b_{ij})_{1 \le j \le n} \in \mathbb{R}^n \; ,
\end{equation}

also
\begin{equation}
A^\mathrm{T} =
\begin{pmatrix*}[r]
\bar{a}_1 & \bar{a}_2 & \ldots & \bar{a}_m
\end{pmatrix*}
\quad \mbox{und} \quad
B =
\begin{pmatrix*}[r]
\bar{b}_1 & \bar{b}_2 & \ldots & \bar{b}_k
\end{pmatrix*} \; .
\end{equation}

Dann gilt
\begin{equation}
AB = \left(\langle \bar{a}_i,\bar{b}_j \rangle \right)_{1 \le i \le m, 1 \le j \le k}
\end{equation}

\end{theorem}

\footnotesize
Bemerkungen

* Der Eintrag $(AB)_{ij}$ enstpricht dem Skalarprodukt von $i$ter Spalte von $A^\mathrm{T}$ und $j$ter Spalte von $B$.
* Der Beweis ergibt sich aus den Definitionen von Matrixmultiplikation und Skalarprodukt.


<!-- Theorem: Summe der Quadrate aller Einträge eines Vektors -->
<!-- Beweis -->
# Operationen

\setstretch{1.2}
\footnotesize
\begin{theorem}[Summe der Quadrate aller Einträge eines Vektors]

\normalfont
\justifying
Es sei $x \in \mathbb{R}^n$ ein $n$-dimensionaler Vektor. Dann kann die Summe der Quadrate aller Einträge dieses Vektors durch die Matrixmultiplikation des transponierten Vektors mit sich selbst berechnet werden:
\begin{equation}
\sum_{i=1}^n x_i^2 = x^\mathrm{T} x \; .
\end{equation}

\end{theorem}

\footnotesize
Bemerkungen

* Es handelt sich um einen Spezialfall des Theorems zum Skalarprodukt als Matrixmultiplikation.
* Im Rahmen des ALM ist das Theorem nützlich, um z.B. die residuelle Quadratsumme auszudrücken.

\vspace{2mm}
\underline{Beweis}

\begin{equation}
x^\mathrm{T} x
=
\begin{pmatrix*}
x_1    \\
x_2    \\
\vdots \\
x_n
\end{pmatrix*}^\mathrm{T}
\begin{pmatrix*}
x_1    \\
x_2    \\
\vdots \\
x_n
\end{pmatrix*}
=
\begin{pmatrix*}
x_1 & x_2 & \ldots & x_n
\end{pmatrix*}
\begin{pmatrix*}
x_1    \\
x_2    \\
\vdots \\
x_n
\end{pmatrix*}
=
x_1^2 + x_2^2 + \ldots + x_n^2
=
\sum_{i=1}^n x_i^2
\end{equation}
$\hfill\Box$


<!-- Theorem: Matrixmultiplikation und Transposition -->
<!-- Beweis -->
# Operationen

\footnotesize
\begin{theorem}[Matrixmultiplikation und Transposition]

\justifying
\normalfont

Es seien $A \in \mathbb{R}^{m \times n}$ und $B \in \mathbb{R}^{n \times k}$. Dann gilt:
\begin{equation}
(AB)^\mathrm{T} = B^\mathrm{T}A^\mathrm{T}.
\end{equation}

\end{theorem}

\underline{Beweis}

\begin{align}
\begin{split}
(AB)^\mathrm{T}
& = \left(\left(\sum_{i=1}^n a_{ji}b_{il} \right)_{1 \le j \le m, 1 \le l \le k}\right)^\mathrm{T} \\
& = \left(\sum_{i=1}^n a_{ij}b_{li} \right)_{1 \le j \le m, 1 \le l \le k}                \\
& = \left(\sum_{i=1}^n b_{li}a_{ij} \right)_{1 \le l \le k, 1 \le j \le m}                \\
& = B^\mathrm{T}A^\mathrm{T}
\end{split}
\end{align}
$\hfill\Box$


<!-- Abschnitt 3: Inverse -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

**Inverse**

Determinanten

Rang und Spur

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Motivation: Inverse Matrix -->
# Inverse

\small
\textcolor{darkblue}{Motivation für Begriff der Inversen einer quadratischen Matrix}

\setstretch{2}
\footnotesize

* Es seien $A\in \mathbb{R}^{n \times n}, x \in \mathbb{R}^n$ und $b \in \mathbb{R}^n$, $A$ und $b$ seien als bekannt vorausgesetzt, $x$ sei unbekannt.
\setstretch{1.5}
* Zum Beispiel sei $A := \begin{pmatrix*}[r] 1 & 2 \\ 3 & 4 \end{pmatrix*}$ und $b := \begin{pmatrix*}[r]  5 \\ 11 \end{pmatrix*}$
* In diesem Fall gilt
$Ax = b
\quad \Leftrightarrow \quad
\begin{pmatrix*}[r] 1 & 2 \\ 3 & 4 \end{pmatrix*} \begin{pmatrix*}[r] x_1 \\ x_2 \end{pmatrix*} = \begin{pmatrix*}[r]  5 \\ 11 \end{pmatrix*}
\quad \Leftrightarrow \quad
\begin{array}{rl}
1x_1 + 2x_2 & = 5 \\
3x_1 + 4x_2 & = 11
\end{array}$
\setstretch{2}
* Wir haben also ein *lineares Gleichungssystem* (LGS) mit zwei Gleichungen und zwei Unbekannten.
* Wir stellen uns vor, dass wir wissen möchten, für welche(s) $x$ das LGS erfüllt ist.
* Wären $A = a \in \mathbb{R}$, $x \in \mathbb{R}$ und $b \in \mathbb{R}$, also $ax = b$
gegeben, so würden wir mit dem *multiplikativem Inversen* von $a$ multiplizieren, also dem
Wert, der mit $a$ multipliziert $1$ ergibt und durch $a^{-1} = \frac{1}{a}$ gegeben ist.
* Dann würde nämlich gelten
$ax = b \quad \Leftrightarrow \quad a^{-1}ax = a^{-1}b \quad \Leftrightarrow \quad 1 \cdot x = a^{-1}b \quad \Leftrightarrow \quad x = \frac{b}{a}$
* Konkret etwa
$2x = 6 \quad \Leftrightarrow \quad 2^{-1} 2x = 2^{-1}6 \quad \Leftrightarrow \quad \frac{1}{2}2x = \frac{1}{2}6 \quad \Leftrightarrow \quad x = 3$.
* Analog möchte man mit dem *multiplikativen Inversen* $A^{-1}$ von $A$ multiplizieren können, sodass "$A^{-1}A = 1$".
* Dann hätte man nämlich $Ax = b \quad \Leftrightarrow \quad A^{-1}Ax = A^{-1}b \quad \Leftrightarrow \quad x = A^{-1}b$
* Diese Idee des multiplikativen Inversen wird im folgenden als *Inverse eine quadratischen Matrix* formalisiert.


<!-- Definition: Einheitsmatrix -->
# Inverse

\footnotesize
\begin{definition}[Einheitsmatrix]

\justifying
Die Matrix $A$ mit $a_{ij} = 1$ für $i = j$ und $a_{ij} = 0$ für $i \neq j$
\begin{equation}
I_n
:= (a_{ij})_{1\le i \le n, 1 \le j \le n}  \in \mathbb{R}^{n \times n}
:=
\begin{pmatrix*}[r]
1      & 0      & \cdots & 0      \\
0      & 1      & \cdots & 0      \\
\vdots & \vdots & \ddots & \vdots \\
0      & 0      & \cdots & 1      \\
\end{pmatrix*}
\end{equation}
heißt \textit{$n$-dimensionale Einheitsmatrix}.

\end{definition}

Bemerkungen

* Die Einheitsmatrix ist eine quadratische Matrix, bei alle diagonalen Einträge 1 und alle anderen 0 sind.
* In R wird $I_n$ mit dem Befehl `diag(n)` erzeugt.


<!-- Definition: Neutrales Element der Matrixmultiplikation -->
# Inverse

\footnotesize
\begin{theorem}[Neutrales Element der Matrixmultiplikation]

\justifying
\normalfont
$I_n$ ist das neutrale Element der Matrixmultiplikation, d.h. es gilt für $A \in \mathbb{R}^{n \times m}$, dass
\begin{equation}
I_n A = A
\quad \mbox{und} \quad
A I_m = A.
\end{equation}

\end{theorem}

\footnotesize
Bemerkungen

* Ist die Matrixmultiplikation der Einheitsmatrix mit einer anderen Matrix definiert, so bleibt letztere dabei unverändert und die Einheitsmatrix "verschwindet" aus dem Produkt.

\vspace{2mm}
\underline{Beweis}

Es sei $B = (b_{ij}) = I_nA \in \mathbb{R}^{n\times m}$. Dann gilt für alle $1 \le i \le n$ und alle $1 \le j \le n$
\begin{equation}
b_{ij}
= 0 \cdot a_{1j}
+ 0 \cdot a_{2j}
+ \cdots
+ 0 \cdot a_{i-1,j}
+ 1 \cdot a_{ij} +
+ 0 \cdot a_{i+1,j}
+ \cdots
+ 0 \cdot a_{nj}
= a_{ij}
\end{equation}
und analog für $AI_m$.
$\hfill\Box$


<!-- Definition: Invertierbare Matrix und inverse Matrix -->
# Inverse

\small
\begin{definition}[Invertierbare Matrix und inverse Matrix]

\justifying
Eine quadratische Matrix $A \in \mathbb{R}^{n \times n}$ heißt \textit{invertierbar}, wenn es eine quadratische Matrix $A^{-1} \in \mathbb{R}^{n \times n}$ gibt, sodass
\begin{equation}
A^{-1}A = AA^{-1} = I_n
\end{equation}
ist. Die Matrix $A^{-1}$ heißt die \textit{inverse Matrix von $A$}.

\end{definition}

\footnotesize
Bemerkungen

* Die inverse Matrix von $A$ heißt auch einfach *Inverse* von $A$.
* Invertierbarkeit und inverse Matrizen beziehen sich nur auf quadratische Matrizen.
* Quadratische Matrizen können, müssen aber nicht invertierbar sein.
* Nicht-invertierbare Matrizen nennt man *singuläre* Matrizen.
* Für $A = a \in \mathbb{R}^{1 \times 1}$ gilt $A^{-1} = \frac{1}{a}$.
* Die Definition sagt nur aus, was eine inverse Matrix ist, aber nicht, wie man sie berechnet.


<!-- Beispiele -->
# Inverse

\small
Beispiel für eine invertierbare Matrix

\footnotesize
Die Matrix
$A = \begin{pmatrix*}[r] 2 & 1 \\ 3 & 4 \end{pmatrix*}$
ist invertierbar mit inverser Matrix
$A^{-1} = \begin{pmatrix*}[r] 0.8 & -0.2 \\ -0.6 & 0.4 \end{pmatrix*}$,
denn
\begin{equation}
\begin{pmatrix*}[r] 2   &  1   \\   3   & 4   \end{pmatrix*}
\begin{pmatrix*}[r] 0.8 & -0.2 \\  -0.6 & 0.4 \end{pmatrix*}
=
\begin{pmatrix*}[r] 1 & 0 \\ 0 & 1 \end{pmatrix*}
=
\begin{pmatrix*}[r] 0.8 & -0.2  \\  -0.6 & 0.4 \end{pmatrix*}
\begin{pmatrix*}[r] 2   &  1    \\   3   & 4   \end{pmatrix*},
\end{equation}
wovon man sich durch Nachrechnen überzeugt.

\vspace{6mm}

\small
Beispiel für eine nicht-invertierbare Matrix

\footnotesize
Die Matrix
$B = \begin{pmatrix*}[r] 1 & 0 \\ 0 & 0 \end{pmatrix*}$
ist nicht invertierbar,
denn wäre $B$ invertierbar, dann gäbe es
$\begin{pmatrix*}[r] a & b \\ c & d \end{pmatrix*}$
mit
\begin{equation}
\begin{pmatrix*}[r] 1 & 0 \\ 0 & 0 \end{pmatrix*}
\begin{pmatrix*}[r] a & b \\ c & d \end{pmatrix*}
=
\begin{pmatrix*}[r] a & b \\ 0 & 0 \end{pmatrix*}
=
\begin{pmatrix*}[r] 1 & 0 \\ 0 & 1 \end{pmatrix*}
\end{equation}
Das würde aber bedeuten, dass $0 = 1$ in $\mathbb{R}$ und das ist ein Widerspruch. Also kann $B$ nicht invertierbar sein.


<!-- Berechnen inverser Matrizen -->
# Inverse

\setstretch{2}
\textcolor{darkblue}{Berechnen inverser Matrizen}

\normalsize
* $2 \times 2$ bis etwa $5 \times 5$ Matrizen kann man prinzipiell per Hand invertieren.
* Dazu lernt man im Bachlor-Studium Mathematik verschiedene Verfahren.
* Wir verzichten auf eine Einführung in die Matrizeninvertierung per Hand.
* Ein kurzes (30 min) Erklärvideo (englisch) [\textcolor{darkblue}{findet sich hier}](https://www.youtube.com/watch?v=9TD6gXfQDkw).
* In der Anwendung werden Matrizen standardmäßig numerisch invertiert.
* Matrixinversion ist ein weites Feld in der numerischen Mathematik.
* Es gibt sehr viele Algorithmen zur Invertierung invertierbarer Matrizen.
* In R berechnet man inverse Matrizen zum Beispiel mit dem Befehl `solve(A)`.


<!-- Berechnen inverser Matrizen -->
# Inverse

\textcolor{darkblue}{Berechnen inverser Matrizen}

\vspace{2mm}
\footnotesize

```{r, echo = T}
# Definition
A = matrix(c(2,1,
             3,4),
           nrow  = 2,
           byrow = TRUE)

# Inverse Matrix
solve(A)                        # A^{-1}
```


<!-- Berechnen inverser Matrizen -->
# Inverse

\textcolor{darkblue}{Berechnen inverser Matrizen}

\vspace{2mm}
\footnotesize
\setstretch{1.2}

```{r, echo = T}
print(solve(A) %*% A)
```

\vspace{2mm}

```{r, echo = T}
print(A %*% solve(A))
```

\vspace{2mm}

```{r, echo = T, error = T}
# nicht-invertierbare Matrizen sind auch numerisch nicht-invertierbar (singulär)
B = matrix(c(1,0,
             0,0),
           nrow  = 2,
           byrow = 2)
solve(B)                        # B^{-1}
```


<!-- Theorem: Inverse einer 2 x 2 Matrix -->
# Inverse

\small
\begin{theorem}[Inverse einer $2 \times 2$ Matrix]

\normalfont
$A \in \mathbb{R}^{2 \times 2}$ sei eine Matrix der folgenden Form:
\begin{equation}
A :=
\begin{pmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} 
\end{pmatrix} \; .
\end{equation}

Dann gilt: Wenn $a_{11} a_{22} - a_{12} a_{21} \neq 0$, dann existiert die Inverse von $A$ und ist gegeben durch
\begin{equation}
A^{-1} =
\frac{1}{a_{11} a_{22} - a_{12} a_{21}}
\begin{pmatrix*}[r]
 a_{22} & -a_{12} \\
-a_{21} &  a_{11}
\end{pmatrix*} \; .
\end{equation}

\end{theorem}

\small
Bemerkungen

* Die Inverse einer $2 \times 2$ Matrix lässt sich mithilfe einer einfachen Formel berechnen.
* Die Inverse einer $2 \times 2$ Matrix vertauscht die Diagonalelemente und multipliziert die Nicht-Diagonalelemente mit $-1$. Das Ergebnis wird dann noch durch die Determinante der Ausgangsmatrix geteilt (siehe nächster Abschnitt).


<!-- Beweis -->
# Inverse

\small
\underline{Beweis}

Für den Fall, dass $a_{11} a_{22} - a_{12} a_{21} \neq 0$, muss gezeigt werden, dass $A^{-1} A = I_2$. Es gilt:
\begin{equation}
\begin{split}
A^{-1} A
& =
\frac{1}{a_{11} a_{22} - a_{12} a_{21}}
\begin{pmatrix*}[r]
 a_{22} & -a_{12} \\
-a_{21} &  a_{11}
\end{pmatrix*}
\begin{pmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22} 
\end{pmatrix} \\
& =
\frac{1}{a_{11} a_{22} - a_{12} a_{21}}
\begin{pmatrix}
  a_{22} a_{11} - a_{12} a_{21} &   a_{22} a_{12} - a_{12} a_{22} \\
- a_{21} a_{11} + a_{11} a_{21} & - a_{21} a_{12} + a_{11} a_{22} \\
\end{pmatrix} \\
& =
\frac{1}{a_{11} a_{22} - a_{12} a_{21}}
\begin{pmatrix}
a_{11} a_{22} - a_{12} a_{21} & 0                             \\
0                             & a_{11} a_{22} - a_{21} a_{12} \\
\end{pmatrix} \\
& =
\begin{pmatrix}
\frac{a_{11} a_{22} - a_{12} a_{21}}{a_{11} a_{22} - a_{12} a_{21}} & 0                                                                   \\
0                                                                   & \frac{a_{11} a_{22} - a_{12} a_{21}}{a_{11} a_{22} - a_{12} a_{21}} \\
\end{pmatrix} \\
& =
\begin{pmatrix}
1 & 0 \\
0 & 1 \\
\end{pmatrix} \\
& = I_2 \; .
\end{split}
\end{equation}
$\hfill\Box$


<!-- Beispiele -->
# Inverse

\small
Beispiel für eine invertierbare Matrix

\footnotesize
Die Matrix
$A = \begin{pmatrix*}[r] 2 & 1 \\ 3 & 4 \end{pmatrix*}$
ist invertierbar, da
$2 \cdot 4 - 1 \cdot 3 = 5 \neq 0$,
und die Inverse ist

\begin{equation}
\begin{split}
A^{-1}
&=
\frac{1}{2 \cdot 4 - 1 \cdot 3}
\begin{pmatrix*}[r]
 4 & -1 \\
-3 &  2
\end{pmatrix*} \\
&=
\frac{1}{5}
\begin{pmatrix*}[r]
 4 & -1 \\
-3 &  2
\end{pmatrix*} \\
&=
\begin{pmatrix*}[r]
 4 \cdot \frac{1}{5} & -1 \cdot \frac{1}{5} \\
-3 \cdot \frac{1}{5} &  2 \cdot \frac{1}{5}
\end{pmatrix*} \\
&=
\begin{pmatrix*}[r]
 0.8 & -0.2 \\
-0.6 &  0.4
\end{pmatrix*} \; .
\end{split}
\end{equation}

\vspace{4mm}

\small
Beispiel für eine nicht-invertierbare Matrix

\footnotesize
Die Matrix
$B = \begin{pmatrix*}[r] 1 & 0 \\ 0 & 0 \end{pmatrix*}$
ist nicht invertierbar, da
$1 \cdot 0 - 0 \cdot 0 = 0$.


<!-- Abschnitt 4: Determinanten -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

Inverse

**Determinanten**

Rang und Spur

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Definition: Determinante -->
# Determinanten

\setstretch{1.2}
\footnotesize
\begin{definition}[Determinante]

\justifying
Für $A = (a_{ij})_{1 \le i,j \le n} \in \mathbb{R}^{n \times n}$ mit $n>1$ sei $A_{ij} \in \mathbb{R}^{(n-1) \times (n-1)}$ die Matrix, die aus $A$ durch Entfernen der $i$ten Zeile und der $j$ten Spalte entsteht. Dann heißt die Zahl
\begin{equation}
\begin{array}{ll}
|A| := a_{11}                                   & \mbox{ für } n = 1 \\
|A| := \sum_{j = 1}^n a_{1j}(-1)^{1+j} |A_{1j}| & \mbox{ für } n > 1
\end{array}
\end{equation}
die \textit{Determinante} von $A$.

\end{definition}

\footnotesize
Bemerkungen

* Für
\begin{equation}
A :=
\begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{pmatrix}
\end{equation}
ergeben sich zum Beispiel
\begin{equation}
A_{11} =
\begin{pmatrix}
5 & 6 \\
8 & 9 \\
\end{pmatrix}, \quad
A_{12} =
\begin{pmatrix}
4 & 6 \\
7 & 9 \\
\end{pmatrix}, \quad
A_{21} =
\begin{pmatrix}
2 & 3 \\
8 & 9 \\
\end{pmatrix}, \quad
A_{22} =
\begin{pmatrix}
1 & 3 \\
7 & 9 \\
\end{pmatrix}
\end{equation}
* Determinanten sind  nichtlineare Abbildungen der Form $|\cdot|: \mathbb{R}^{n \times n} \to \mathbb{R}, A \mapsto |A|$.


<!-- Theorem: Determinanten von 2 x 2 und 3 x 3 Matrizen -->
# Determinanten

\footnotesize
\setstretch{1.2}
\begin{theorem}[Determinanten von $2\times 2$ und $3\times 3$ Matrizen]

\normalfont
(1) Es sei $A = (a_{ij})_{1 \le i,j \le 2} \in \mathbb{R}^{2 \times 2}$. Dann gilt
\begin{equation}
|A| = a_{11}a_{22} - a_{12}a_{21}.
\end{equation}

(2) Es sei $A = (a_{ij})_{1 \le i,j \le 3} \in \mathbb{R}^{3 \times 3}$. Dann gilt
\begin{align}
\begin{split}
|A|
= a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32}
- a_{12}a_{21}a_{33} - a_{11}a_{23}a_{32} - a_{13}a_{22}a_{31}.
\end{split}
\end{align}
\end{theorem}

Bemerkungen

* Die Determinante einer $1 \times 1$ Matrix ist identisch mit ihrem einzigen Eintrag.
* Für $2 \times 2$ und $3 \times 3$ Matrizen (und nur für diese) gilt die *Sarrusche Merkregel*:
\begin{center}
``Summe der Produkte auf den Diagonalen minus Summe der Produkte auf den Gegendiagonalen''
\end{center}
* Bei $3 \times 3$ Matrizen bezieht sich die Merkregel auf das Schema
\begin{equation}
\begin{pmatrix}
a_{11} & a_{12} & a_{13} & \vert & a_{11} & a_{12} \\
a_{21} & a_{22} & a_{23} & \vert & a_{21} & a_{22} \\
a_{31} & a_{32} & a_{33} & \vert & a_{31} & a_{32}
\end{pmatrix} \; .
\end{equation}


<!-- Beweis -->
# Determinanten

\scriptsize
\setstretch{1}
\underline{Beweis}

Für $A \in \mathbb{R}^{2 \times 2}$ gilt nach Definition
\begin{align}
\begin{split}
|A|
& = \sum_{j = 1}^n a_{1j}(-1)^{1+j} |A_{1j}| \\
& = a_{11}(-1)^{1 + 1}|A_{11}| + a_{12}(-1)^{1 + 2}|A_{12}| \\
& = a_{11}|(a_{22})| - a_{12}|(a_{21})| \\
& = a_{11}a_{22} - a_{12}a_{21}. \\
\end{split}
\end{align}

Für $A \in \mathbb{R}^{3 \times 3}$ gilt nach Definition und mit der Formel für die Determinante von $2 \times 2$ Matrizen
\begin{align}
\begin{split}
|A|
& = \sum_{j=1}^n a_{1j}(-1)^{1+j} |A_{1j}| \\
& =   a_{11}(-1)^{1+1} |A_{1j}| + a_{12}(-1)^{1+2} |A_{12}| +  a_{13}(-1)^{1+3}|A_{13}| \\
& =   a_{11}|A_{11}| - a_{12}|A_{12}| + a_{13}|A_{13}| \\
& =   a_{11}\left\vert\begin{pmatrix} a_{22} & a_{23} \\ a_{32} & a_{33}\end{pmatrix}\right\vert
    - a_{12}\left\vert\begin{pmatrix} a_{21} & a_{23} \\ a_{31} & a_{33}\end{pmatrix}\right\vert
    + a_{13}\left\vert\begin{pmatrix} a_{21} & a_{22} \\ a_{31} & a_{32}\end{pmatrix}\right\vert \\
& =   a_{11}(a_{22}a_{33} - a_{23}a_{32})
    - a_{12}(a_{21}a_{33} - a_{23}a_{31})
    + a_{13}(a_{21}a_{32} - a_{22}a_{31}) \\
& =   a_{11}a_{22}a_{33} - a_{11}a_{23}a_{32}
    - a_{12}a_{21}a_{33} + a_{12}a_{23}a_{31}
    + a_{13}a_{21}a_{32} - a_{13}a_{22}a_{31} \\
& =   a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32}
    - a_{12}a_{21}a_{33} - a_{11}a_{23}a_{32} - a_{13}a_{22}a_{31}.
\end{split}
\end{align}
$\hfill\Box$


<!-- Beispiele -->
# Determinanten

\small
Beispiel 1

\footnotesize
Es seien
\begin{equation}
A :=
\begin{pmatrix}
2 & 1 \\
3 & 4
\end{pmatrix}
\quad \mbox{und} \quad
B :=
\begin{pmatrix}
1 & 0 \\
0 & 0
\end{pmatrix} \; .
\end{equation}

Dann ergeben sich
\begin{equation}
|A| = 2 \cdot 4 - 1 \cdot 3 = 8 - 3 = 5
\end{equation}
und
\begin{equation}
|B| = 1 \cdot 0 - 0 \cdot 0 = 0 - 0 = 0 \; .
\end{equation}
\vspace{2mm}

\small
Beispiel 2

\footnotesize
Es sei
\begin{equation}
C :=
\begin{pmatrix}
2 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 3
\end{pmatrix} \; .
\end{equation}

Dann ergibt sich
\begin{equation}
|C|
= 2 \cdot 1 \cdot 3
+ 0 \cdot 0 \cdot 0
+ 0 \cdot 0 \cdot 0
- 0 \cdot 0 \cdot 3
- 0 \cdot 0 \cdot 0
- 0 \cdot 1 \cdot 0
= 2 \cdot 1 \cdot 3
= 6 \; .
\end{equation}


<!-- Beispiele in R -->
# Determinanten

\setstretch{1}
\footnotesize

```{r, echo = T}
# Beispiel 1
A = matrix(c(2,1,                  # Matrixdefinition
             3,4),
           nrow = 2,
           byrow = TRUE)
det(A)                             # Determinantenberechnung
```

\vspace{2mm}

```{r, echo = T}
# Beispiel 1
B = matrix(c(1,0,                  # Matrixdefinition
             0,0),
           nrow = 2,
           byrow = TRUE)
det(B)                             # Determinantenberechnung
```

\vspace{2mm}

```{r, echo = T}
# Beispiel 2
C = matrix(c(2,0,0,                # Matrixdefinition
             0,1,0,
             0,0,3),
           nrow = 3,
           byrow = TRUE)
det(C)                             # Determinantenberechnung
```


<!-- Theorem: Rechenregeln für Determinanten -->
# Determinanten

\footnotesize
\begin{theorem}[Rechenregeln für Determinanten]

\normalfont
(\textit{Determinantenmultiplikationssatz}) Für $A,B \in \mathbb{R}^{n \times n}$ gilt
\begin{equation}
|AB| = |A||B|.
\end{equation}

(\textit{Transposition}) Für $A \in \mathbb{R}^{n \times n}$ gilt
\begin{equation}
|A| = \left\vert A^\mathrm{T} \right\vert.
\end{equation}

(\textit{Inversion}) Für eine invertierbare Matrix $A \in \mathbb{R}^{n \times n}$ gilt
\begin{equation}
\left\vert A^{-1}\right\vert = \frac{1}{|A|}
\end{equation}

(\textit{Dreiecksmatrizen}) Für Dreiecksmatrizen, d.h. eine Matrix $A = (a_{ij})_{1 \le i,j\le n} \in \mathbb{R}^{n \times n}$ mit $a_{ij} = 0$ für $i > j$ oder $a_{ij} = 0$ \mbox{ für } $j > i$, ist die Determinante gleich dem Produkt der Diagonalelemente:
\begin{equation}
|A| = \prod_{i=1}^n a_{ii}
\end{equation}

\end{theorem}

\footnotesize
Bemerkungen

* Wir verzichten auf einen Beweis.
* Bei Dreiecksmatrizen sind alle Elemente unterhalb ($i > j$) oder oberhalb ($j > i$) der Diagonalen 0.
* Bei $I_n$ sind alle nicht-diagonalen Elemente 0 und alle diagonalen Elemente 1, also folgt $|I_n| = 1$.


<!-- Theorem: Invertierbarkeit und Determinante -->
<!-- Beweisandeutung -->
# Determinanten

\small
\begin{theorem}[Invertierbarkeit und Determinante]

\normalfont
$A \in \mathbb{R}^{n \times n}$ ist dann und nur dann invertierbar, wenn $|A| \neq 0$ ist. Es gilt also
\begin{align}
\begin{split}
A \mbox{ ist invertierbar} \Leftrightarrow |A| \neq 0
\quad \mbox{und} \quad
A \mbox{ ist nicht invertierbar} \Leftrightarrow |A| = 0 \; .
\end{split}
\end{align}

\end{theorem}

\footnotesize
\underline{Beweisandeutung}
\vspace{1mm}

Wir zeigen lediglich, dass aus der Invertierbarkeit von $A$ folgt, dass $|A|$ nicht null sein kann. Nehmen wir also an, dass $A$ invertierbar ist. Dann gibt es eine Matrix $B$ mit $AB = I_n$ und mit dem Determinantenmultiplikationssatz folgt
\begin{equation}
|AB| = |A||B| = |I_n| = 1.
\end{equation}
Also kann nicht $|A| = 0$ gelten, denn sonst wäre $0 = 1$.
$\hfill\Box$


<!-- Visuelle Intuition -->
# Determinanten

\textcolor{darkblue}{Visuelle Intuition}

\small
$a_1,...,a_n \in \mathbb{R}^n$  seien die Spalten von $A \in \mathbb{R}^{n \times n}$.

$\Rightarrow |A|$ enstpricht dem signierten Volumen des von $a_1,...,a_n \in \mathbb{R}^n$ aufgespannten Parallelotops.

```{r, echo = F, eval = F}
graphics.off()
dev.new()
par(
    family      = "sans",
    mfcol       = c(1,3),
    pty         = "s",
    bty         = "l",
    lwd         = 1,
    las         = 1,
    mgp         = c(2,1,0),
    xaxs        = "i",
    yaxs        = "i",
    font.main   = 1,
    cex         = 1.2,
    cex.main    = 1.2)

# Vektordefinitionen
x = c(1,2)
y = c(3,1)
z = c(4,3)

# Visualisierung
plot(NULL,
    xlab        = TeX("$x_1$"),
    ylab        = TeX("$x_2$"),
    xlim        = c(0,4),
    ylim        = c(0,4))
grid()
points(c(x[1],y[1]), c(x[2],y[2]),
    pch         = 19)
arrows(
    x0          = c(0,0,x[1],y[1]),
    y0          = c(0,0,x[2],y[2]),
    x1          = c(x[1],y[1],z[1],z[1]),
    y1          = c(x[2],y[2],z[2],z[2]),
    angle       = 20,
    length      = .1,
    col         = c("black", "black","gray60", "gray60"))

# Vektordefinitionen
x = c(2,0)
y = c(0,2)
z = x + y

# Visualisierung
plot(NULL,
    xlab        = TeX("$x_1$"),
    ylab        = TeX("$x_2$"),
    xlim        = c(0,4),
    ylim        = c(0,4))
grid()
points(c(x[1],y[1]), c(x[2],y[2]),
    pch         = 19)
arrows(
    x0          = c(0,0,x[1],y[1]),
    y0          = c(0,0,x[2],y[2]),
    x1          = c(x[1],y[1],z[1],z[1]),
    y1          = c(x[2],y[2],z[2],z[2]),
    angle       = 20,
    length      = .1,
    col         = c("black", "black","gray60", "gray60"),
    xpd         = TRUE)

# Vektordefinitionen
x = c(2,2)
y = c(2,2)
z = x + y

# Visualisierung
plot(NULL,
    xlab        = TeX("$x_1$"),
    ylab        = TeX("$x_2$"),
    xlim        = c(0,4),
    ylim        = c(0,4))
grid()
points(c(x[1],y[1]), c(x[2],y[2]),
    pch         = 19)
arrows(
    x0          = c(0,0,x[1],y[1]),
    y0          = c(0,0,x[2],y[2]),
    x1          = c(x[1],y[1],z[1],z[1]),
    y1          = c(x[2],y[2],z[2],z[2]),
    angle       = 20,
    length      = .1,
    col         = c("black", "black","gray60", "gray60"),
    xpd         = TRUE)

# export to pdf
dev.copy2pdf(
    file   = file.path(fdir, "determinante_JS.pdf"),
    width  = 12,                                                          
    height = 4)                                                           
```

\footnotesize
\begin{equation*}
A_1 =
\begin{pmatrix}
3 & 1 \\
1 & 2
\end{pmatrix}
\quad\quad\quad\quad\quad\quad\quad\quad\quad
A_2 =
\begin{pmatrix}
2 & 0 \\
0 & 2
\end{pmatrix}
\quad\quad\quad\quad\quad\quad\quad\quad\quad
A_3 =
\begin{pmatrix}
2 & 2 \\
2 & 2
\end{pmatrix}
\end{equation*}

```{r, echo = F, out.width = "100%"}
knitr::include_graphics("Abbildungen/determinante.pdf")
```

\vspace{-5mm}
\begin{equation*}
|A_1| = 3\cdot 2 - 1 \cdot 1 = 5
\quad\quad\quad\quad\quad\quad
|A_2| = 2\cdot 2 - 0 \cdot 0 = 4
\quad\quad\quad\quad\quad\quad
|A_3| = 2\cdot 2 - 2 \cdot 2 = 0
\end{equation*}


<!-- Anekdote -->
# Determinanten

\textcolor{darkblue}{Anekdote: Herkunft des Ausdrucks ``Matrix''}

\vspace{2mm}
```{r, echo = F, out.width = "35%", fig.align = "center"}
knitr::include_graphics("Abbildungen/james_joseph_sylvester.jpg")
```

\vspace{1mm}
\center
James Joseph Sylvester (1814 -- 1897)

\vspace{2mm}
\footnotesize
(Quelle: [*Wikimedia Commons*: "James_Joseph_Sylvester.jpg"](https://commons.wikimedia.org/wiki/File:James_Joseph_Sylvester.jpg); Lizenz: gemeinfrei.)

<!-- Der Begriff der Determinante existierte bereits vor dem Konzept der Matrix. Als James Joseph Sylvester 1850 die Matrizen einführte, nannte er sie "Matrix", also lateinisch für "Gebärmutter", weil die Matrix der Ort ist, an dem die Determinanten geboren werden. -->


<!-- Abschnitt 5: Rang und Spur -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

Inverse

Determinanten

**Rang und Spur**

Spezielle Matrizen

Selbstkontrollfragen

\vfill


<!-- Überblick -->
# Rang und Spur

\small
Überblick

\footnotesize
\setstretch{2}
* Der Rang einer Matrix ist eine Zahl, an der bestimmte Eigenschaften der Matrix abgelesen werden können.
* In dieser Hinsicht ist der Rang einer Matrix sehr ähnlich zur Determinante einer Matrix.
* Viele Resultate in der linearen Algebra beruhen auf Annahmen über den Rang einer Matrix.
* Wir werden z.B. durchgängig annehmen, dass die Designmatrix des ALMs *vollen Spaltenrang* hat.
* Der Rang einer Matrix ist ein tiefgehendes Konzept, das wir hier nur oberflächlich behandeln können.
* Für ausführlichere Einführungen, siehe z.B. @searle1982, Kapitel 6 und @strang2009, Kapitel 3.2.


<!-- Definition: Spaltenraum einer Matrix -->
# Rang und Spur

\footnotesize
\begin{definition}[Spaltenraum einer Matrix]

\justifying
$X \in \mathbb{R}^{n \times p}$ sei eine Matrix mit $n>p$ und es seien $x_1,...,x_p\in\mathbb{R}^n$ die Spalten von $X$. Dann wird die Menge aller Linearkombinationen von $x_1,...,x_p\in\mathbb{R}^n$ (= die lineare Hülle der $x_1,...,x_p\in\mathbb{R}^n$) \textit{Spaltenraum von $X \in \mathbb{R}^{n \times p}$} genannt und mit $\mathcal{S}(X)$ bezeichnet. Insbesondere gilt
\begin{equation}
\mathcal{S}(X) = \left\lbrace X\beta \in \mathbb{R}^n \; \vert \; \beta \in \mathbb{R}^p \right\rbrace.
\end{equation}
\end{definition}

Bemerkungen

* Ohne Beweis halten wir fest, dass $\mathcal{S}(X)$ ein Untervektorraum von $\mathbb{R}^n$ ist.
* Die Menge aller Linearkombinationen von $x_1,...,x_p\in \mathbb{R}^n$ hat die Form
\begin{equation}
\left\lbrace \sum_{i=1}^p \beta_i x_i \; \middle\vert \; x_i \in \mathbb{R}^n, \beta_i \in \mathbb{R} \right\rbrace.
\end{equation}
* Die Form des Spaltenraums in der obigen Definition ergibt sich für $x_{ij} \in \mathbb{R}, 1 \le i \le n, 1 \le j \le p$  durch
\small
\begin{equation*}
X\beta
=
\begin{pmatrix}
\sum_{j=1}^p x_{1j}\beta_j \\ \vdots \\ \sum_{j=1}^p x_{nj}\beta_j
\end{pmatrix}
=
\begin{pmatrix}
\sum_{j=1}^p \beta_j x_{1j} \\ \vdots \\ \sum_{j=1}^p \beta_j x_{nj}
\end{pmatrix}
=
\beta_1
\begin{pmatrix}
x_{11} \\ \vdots \\ x_{n1}
\end{pmatrix}
+\cdots + \beta_p
\begin{pmatrix}
x_{1p} \\ \vdots \\ x_{np}
\end{pmatrix}
= \sum_{i=1}^p \beta_i x_i.
\end{equation*}


<!-- Definition: Rang einer Matrix -->
<!-- Eigenschaften -->
# Rang und Spur

\footnotesize
\begin{definition}[Rang einer Matrix]

\justifying
$X \in \mathbb{R}^{n \times p}$ sei eine Matrix. Dann wird die Dimension des Spaltenraums von $X$ der \textit{Rang von $X$} genannt und mit \mbox{rg(X)} bezeichnet. Gilt dabei $\mbox{rg}(X) = p$, so sagt man, dass $X$ \textit{vollen Spaltenrang} hat.

\end{definition}

\setstretch{1.5}
Bemerkungen

* Ohne Beweis halten wir untenstehend einige wichtige Eigenschaften des Rangs einer Matrix fest.
* Der Rang einer Matrix entspricht der Anzahl der linear unabhängigen Spaltenvektoren der Matrix.
* Es gilt: $\mbox{rg}(X) = \mbox{rg}(X^\mathrm{T})$.
* Für $A \in \mathbb{R}^{p \times p}$ gilt: $\mbox{rg}(A) = p \Leftrightarrow$ $A$ ist invertierbar.
* Für $X \in \mathbb{R}^{n \times p}$ gilt: $\mbox{rg}(X) = \mbox{rg}(X^\mathrm{T}X) = \mbox{rg}(XX^\mathrm{T})$.
* Für $X \in \mathbb{R}^{n \times p}$ gilt damit: $\mbox{rg}(X) = p \Leftrightarrow X^\mathrm{T}X\in \mathbb{R}^{p \times p}$ ist invertierbar.
* Die Funktion `Rank()` aus dem R-Paket `pracma` erlaubt die Berechnung des Rangs einer Matrix.
* Das Spaltenraum- und Rangkonzept einer Matrix erlauben einen geometrischen Zugang zur Theorie des ALMs.
* Wir verfolgen diesen geometrischen Zugang hier nicht. Für Details, siehe z.B. @christensen2011.


<!-- Beispiel zu linearer Unabhängigkeit -->
# Rang und Spur

\normalsize
Beispiel zu linearer Unabhängigkeit
\vspace{2mm}

\footnotesize
Die Vektoren
\begin{equation}
a_1 = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}, \;
a_2 = \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}, \;
a_3 = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}
\end{equation}
sind linear unabhängig, weil sich keiner der Vektoren als Linearkombination der anderen Vektoren darstellen lässt. Die Matrix $A = \begin{pmatrix} a_1 & a_2 & a_3 \end{pmatrix}$ hat also den vollen Spaltenrang $\mbox{rg}(A) = 3$.

\vspace{2mm}
Die Vektoren
\begin{equation}
b_1 = \begin{pmatrix*}[r] 2 \\-1 \\ 1 \\-2 \end{pmatrix*}, \;
b_2 = \begin{pmatrix*}[r] 1 \\ 0 \\ 1 \\ 0 \end{pmatrix*}, \;
b_3 = \begin{pmatrix*}[r] 4 \\-1 \\ 3 \\-2 \end{pmatrix*}
\end{equation}
sind hingegen linear abhängig, da sie sich gegenseitig als Linearkombinationen darstellen lassen. So ist z.B. der dritte Vektor die Summe des ersten Vektors und des mit 2 multiplizierten zweiten Vektors:
\begin{equation}
b_1 + 2 \cdot b_2
=
\begin{pmatrix*}[r] 2 \\-1 \\ 1 \\-2 \end{pmatrix*} + 2 \cdot
\begin{pmatrix*}[r] 1 \\ 0 \\ 1 \\ 0 \end{pmatrix*}
=
\begin{pmatrix*}[r] 2 + 2 \cdot 1 \\-1 + 2 \cdot 0 \\ 1 + 2 \cdot 1 \\-2 + 2 \cdot 0 \end{pmatrix*}
= 
\begin{pmatrix*}[r] 4 \\-1 \\ 3 \\-2 \end{pmatrix*}
=
b_3 \; .
\end{equation}

Die Matrix $B = \begin{pmatrix} b_1 & b_2 & b_3 \end{pmatrix}$ hat also nicht den vollen Spaltenrang, sondern $\mbox{rg}(B) = 2$.


<!-- Beispiel in R -->
# Rang und Spur

\normalsize
Beispiel zu linearer Unabhängigkeit

\vspace{2mm}
\footnotesize

```{r, echo = T}
library(pracma)

# Definitionen
a_1 = matrix(c( 1, 0, 0), nrow = 3)
a_2 = matrix(c( 0, 1, 0), nrow = 3)
a_3 = matrix(c( 0, 0, 1), nrow = 3)
A   = cbind(a_1, a_2, a_3)             # Matrix A

# Definitionen
b_1 = matrix(c( 2,-1, 1,-2), nrow = 4)
b_2 = matrix(c( 1, 0, 1, 0), nrow = 4)
b_3 = matrix(c( 4,-1, 3,-2), nrow = 4)
B   = cbind(b_1, b_2, b_3)             # Matrix B

# Rang
print(Rank(A))                         # rg(A)
print(Rank(B))                         # rg(B)
```


<!-- Definition: Spur einer Matrix -->
<!-- Eigenschaften -->
# Rang und Spur

\footnotesize
\begin{definition}[Spur einer Matrix]

\justifying
$A \in \mathbb{R}^{n \times n}$ sei eine quadratische Matrix. Dann ist die \textit{Spur von $A$} die Summe der Elemente auf der Hauptdiagonale dieser Matrix und wird mit \mbox{sp(A)} bezeichnet:
\begin{equation}
\mbox{sp}(A) = \sum_{i=1}^n a_{ii} \; .
\end{equation}

\end{definition}

\setstretch{1.5}
Bemerkungen

* Ohne Beweis halten wir untenstehend einige wichtige Eigenschaften der Spur einer Matrix fest.
* Es gilt: $\mbox{sp}(A) = \mbox{sp}(A^\mathrm{T})$.
* Für $A,B \in \mathbb{R}^{n \times n}$ gilt: $\mbox{sp}(A+B) = \mbox{sp}(A) + \mbox{sp}(B)$.
* Für $A,B,C \in \mathbb{R}^{n \times n}$ gilt: $\mbox{sp}(ABC) = \mbox{sp}(CAB) = \mbox{sp}(BCA)$.
* Für $A \in \mathbb{R}^{n \times n}$ gilt: $AA = A \Rightarrow \mbox{sp}(A) = \mbox{rg}(A)$.
* Die Spur der Einheitsmatrix ist: $\mbox{sp}(I_n) = n$.
* In R kann die Spur einer Matrix mit `sum(diag(A))` berechnet werden.
* Der Begriff der Spur ist beim Beweis der Verteilung der residuellen Quadratsumme im ALM von Bedeutung.


<!-- Beispiele -->
# Rang und Spur

\small
Beispiel 1

\footnotesize
Es sei
\begin{equation}
A :=
\begin{pmatrix}
2 & 1 \\
3 & 4
\end{pmatrix} \; .
\end{equation}

Dann ergibt sich
\begin{equation}
\mbox{sp}(A) = 2 + 4 = 6 \; .
\end{equation}
\vspace{2mm}

\small
Beispiel 2

\footnotesize
Es sei
\begin{equation}
B :=
\begin{pmatrix}
2 & 7 & 5 & 2 \\
8 & 3 & 5 & 6 \\
6 & 4 & 0 & 9 \\
9 & 2 & 1 & 2
\end{pmatrix} \; .
\end{equation}

Dann ergibt sich
\begin{equation}
\mbox{sp}(B) = 2 + 3 + 0 + 2 = 7 \; .
\end{equation}


<!-- Beispiel in R -->
# Rang und Spur

\small
Beispiel

\vspace{2mm}
\footnotesize

```{r, echo = T}
# Definitionen
A = matrix(c(2,1,        # Matrix A
             3,4),
           nrow  = 2,
           byrow = TRUE)
B = matrix(c(2,7,5,2,    # Matrix B
             8,3,5,6,
             6,4,0,9,
             9,2,1,2),
           nrow  = 4,
           byrow = TRUE)

# Spur
print(sum(diag(A)))      # sp(A)
print(sum(diag(B)))      # sp(B)
```


<!-- Abschnitt 6: Spezielle Matrizen -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

Inverse

Determinanten

Rang und Spur

**Spezielle Matrizen**

Selbstkontrollfragen

\vfill


<!-- Definition: Nullmatrizen und Einsmatrizen -->
<!-- Eigenschaften -->
# Spezielle Matrizen

\footnotesize
\begin{definition}[Nullmatrizen und Einsmatrizen]

\begin{itemize}

\item Wir bezeichnen \textit{Nullmatrizen} (und \textit{Nullvektoren}) mit
\begin{equation}
0_{nm} := (0)_{1 \le i \le n, 1 \le j \le m} \in \mathbb{R}^{n \times m}
\quad \mbox{und} \quad
0_{n} := (0)_{1 \le i \le n} \in \mathbb{R}^{n}
\end{equation}

\item Wir bezeichnen \textit{Einsmatrizen} (und \textit{Einsvektoren}) mit
\begin{equation}
1_{nm} := (1)_{1 \le i \le n, 1 \le j \le m} \in \mathbb{R}^{n \times m}
\quad \mbox{und} \quad
1_n := (1)_{1 \le i \le n} \in \mathbb{R}^n
\end{equation}

\end{itemize}

\end{definition}

Bemerkungen

* $0_{nm}$ und $0_{n}$ bestehen nur aus Nullen.
* $1_{nm}$ und $1_{n}$ bestehen nur aus Einsen.
* Es gelten zum Beispiel
\begin{equation}
0_n 0_m^\mathrm{T} = 0_{nm}
\end{equation}
und
\begin{equation}
1_n 1_m^\mathrm{T} = 1_{nm}.
\end{equation}


<!-- Definition: Einheitsmatrizen und Einheitsvektoren -->
<!-- Eigenschaften -->
# Spezielle Matrizen

\footnotesize
\begin{definition}[Einheitsmatrizen und Einheitsvektoren]

\begin{itemize}

\item Wir bezeichnen die \textit{Einheitsmatrix} als
\begin{equation}
I_{n} := (i_{jk})_{1 \le j \le n, 1 \le k \le n} \in \mathbb{R}^{n \times n}
\quad \mbox{mit} \quad
i_{jk} = 1 \mbox{ für } j = k
\quad \mbox{und} \quad
i_{jk} = 0 \mbox{ für } j \neq k.
\end{equation}

\item Wir bezeichnen die \textit{Einheitsvektoren} $e_i, i = 1,...,n$ als
\begin{equation}
e_{i} := (e_{{i}_j})_{1 \le j \le n} \in \mathbb{R}^{n}
\quad \mbox{mit} \quad
e_{{i}_j} = 1 \mbox{ für } i = j
\quad \mbox{und} \quad
e_{{i}_j} = 0 \mbox{ für } i \neq j.
\end{equation}

\end{itemize}

\end{definition}

Bemerkungen

* $I_n$ besteht nur aus Nullen und Diagonalelementen gleich Eins.
* $e_i, i = 1,....,n$ besteht nur aus Nullen und einer Eins in der $i$ten Komponente.
* Es gilt
\begin{equation}
I_n = \begin{pmatrix} e_1 & e_2 & \ldots & e_n \end{pmatrix}
\end{equation}
* Es gilt auch
\begin{equation}
I_n = \left( e^\mathrm{T}_i e_j \right)_{1 \le j \le n, 1 \le k \le n}
\end{equation}
* Es gelten weiterhin für $1 \le i,j \le n$
\begin{equation}
e^\mathrm{T}_i e_j = 0 \mbox{ für } i \neq j \mbox{ sowie } e^\mathrm{T}_i e_i = 1
\quad \mbox{und} \quad
e^\mathrm{T}_i v = v^\mathrm{T} e_i = v_i \mbox{ für } v \in \mathbb{R}^n.
\end{equation}


<!-- Definition: Diagonalmatrix -->
<!-- Eigenschaften -->
# Spezielle Matrizen

\footnotesize
\begin{definition}[Diagonalmatrix]

\justifying
Eine Matrix $D \in \mathbb{R}^{n \times m}$ heißt \textit{Diagonalmatrix}, wenn $d_{ij} = 0$ für $1 \le i \le n, 1 \le j \le m$ mit $i \neq j$.

\end{definition}

Bemerkungen

* \justifying Eine Diagonalmatrix $D\in \mathbb{R}^{n \times n}$ mit Diagonalelementen $d_1,...,d_n$ schreibt man auch als
\begin{equation}
D = \mbox{diag}(d_1,...,d_n).
\end{equation}
* Diagonalmatrizen haben viele "gute" Eigenschaften.
* Zum Beispiel überzeugt man sich leicht davon, dass Multiplikation einer Matrix $A$
von links mit einer Diagonalmatrix $D$ der Multiplikation der Zeilen der Matrix $A$
mit den entsprechenden Diagonaleinträgen von $D$ entspricht. Die Multiplikation von rechts entspricht der Multiplikation der Spalten von $A$ mit
den entsprechenden Diagonaleinträgen von $D$.
* Eine weitere wichtige Eigenschaft ist
\begin{equation}
D := \mbox{diag}(d_1,...,d_n)
\quad \Rightarrow \quad
|D| = \prod_{i=1}^n d_i
\end{equation}
* Für Beweise dieser Eigenschaften wird auf die einschlägige Literatur, z.B. @searle1982, verwiesen.


<!-- Definition: Symmetrische Matrix -->
<!-- Eigenschaften -->
# Spezielle Matrizen

\footnotesize
\begin{definition}[Symmetrische Matrix]

\justifying
Eine Matrix $S \in \mathbb{R}^{n \times n}$ heißt \textit{symmetrisch}, wenn gilt dass $S^\mathrm{T} = S$.

\end{definition}

Bemerkungen

* Eine symmetrische Matrix ist eine Matrix, deren Transponiertes gleich ihr selbst ist.
* Symmetrische Matrizen haben viele "gute" Eigenschaften.
* Beispielweise gilt für die Summe zweier symmetrischer Matrizen, dass auch diese wieder symmetrisch ist
\begin{equation}
A = A^\mathrm{T}
\quad \mbox{und} \quad
B = B^\mathrm{T}
\quad \Rightarrow \quad
A + B = (A + B)^\mathrm{T}
\end{equation}
und dass die Inverse einer symmetrischen Matrix, sofern sie existiert, auch symmetrisch ist,
\begin{equation}
S^\mathrm{T} = S
\quad \Rightarrow \quad
\left(S^{-1}\right)^\mathrm{T} = S^{-1}.
\end{equation}
* Für Beweise dieser Eigenschaften wird auf die einschlägige Literatur, z.B. @searle1982, verwiesen.


<!-- Definition: Positiv-definite Matrix -->
<!-- Eigenschaften -->
# Spezielle Matrizen

\footnotesize
\begin{definition}[Positiv-definite Matrix]

\justifying
Eine Matrix $C \in \mathbb{R}^{n \times n}$ heißt \textit{positiv-definit} ($\mbox{p.d.}$), wenn
\begin{itemize}
\item $C$ eine symmetrische Matrix ist und
\item für alle $x \in \mathbb{R}^n, x \neq 0_n$ gilt, dass $x^\mathrm{T}Cx > 0$ ist.
\end{itemize}

\end{definition}

\footnotesize

Bemerkungen

* Positiv-definite Matrizen sind für die Definition der multivariaten Normalverteilungen grundlegend.
* Positiv-definite Matrizen haben viele "gute" Eigenschaften.
* Beispielsweise gilt
\begin{equation}
C \mbox{ ist positiv-definit }
\quad \Rightarrow \quad
C^{-1} \mbox{ existiert und ist ebenfalls positiv-definit}.
\end{equation}
* Für Beweise dieser Eigenschaften wird auf die einschlägige Literatur, z.B. @searle1982, verwiesen.


<!-- Anhang: Selbstkontrollfragen -->
#

\large
\setstretch{2}
\vfill

Definition

Operationen

Inverse

Determinanten

Rang und Spur

Spezielle Matrizen

**Selbstkontrollfragen**

\vfill


<!-- Selbstkontrollfragen -->
# Selbstkontrollfragen

\footnotesize
\begin{enumerate}

\item Geben Sie die Definition einer Matrix wieder.
\item Nennen Sie sechs Matrixoperationen.
\item Geben Sie die Definitionen der Matrixaddition und -subtraktion wieder.
\item Geben Sie die Definition der Skalarmultiplikation für Matrizen wieder.
\item Geben Sie die Definition der Matrixtransposition wieder.
\item Es seien
\begin{equation}
A :=
\begin{pmatrix*}[r]
1 & 2 \\
2 & 1
\end{pmatrix*}, \;
B :=
\begin{pmatrix*}[r]
3 & 0 \\
1 & 2
\end{pmatrix*}
\mbox{ und }
c := 2
\end{equation}
Berechnen Sie
\begin{equation}
D := c\left(A - B^\mathrm{T}\right)
\mbox{ und }
E := \left(cA\right)^\mathrm{T} + B
\end{equation}
per Hand.
\item Geben Sie die Definition der Matrixmultiplikation wieder.
\item Es seien $A \in \mathbb{R}^{3 \times 2}, B \in \mathbb{R}^{2\times 4}$ und $C \in \mathbb{R}^{3 \times 4}$. Prüfen Sie, ob folgende Matrixprodukte definiert sind, und wenn ja, geben Sie die Größe der resultierenden Matrix an:
\begin{equation}
ABC, \quad\quad ABC^\mathrm{T}, \quad\quad A^\mathrm{T}CB^\mathrm{T}, \quad\quad BAC.
\end{equation}

\end{enumerate}

```{r, echo = F, eval = F}
# Definitionen
A = matrix(c(1,2,
             2,1),
           nrow  = 2,
           byrow = TRUE)
B = matrix(c(3,0,
             1,2),
           nrow  = 2,
           byrow = TRUE)
c = 2

# Evaluation
print(A)
print(B)
print(c*(A - t(B)))
print(t(c*A) + B)
```

```{r, echo = F, eval = F}
A = matrix(rnorm(6) , nrow = 3)
B = matrix(rnorm(8) , nrow = 2)
C = matrix(rnorm(12), nrow = 3)
print(A)
print(B)
print(C)
print(A %*% B %*% t(C))
print(t(A) %*% C %*% t(B))
```


<!-- Selbstkontrollfragen -->
# Selbstkontrollfragen

\footnotesize
\begin{enumerate}
\setcounter{enumi}{8}

\item Es seien
\begin{equation}
A :=
\begin{pmatrix*}[r]
1 & 2 & 3 \\
4 & 5 & 6 \\
3 & 2 & 0
\end{pmatrix*}, \;
B :=
\begin{pmatrix*}[r]
1 & 2 & 2 \\
1 & 3 & 1 \\
2 & 0 & 0
\end{pmatrix*}
\mbox{ und }
C :=
\begin{pmatrix*}[r]
1 \\ 3 \\ 2
\end{pmatrix*}.
\end{equation}
Berechnen Sie die Matrixprodukte
\begin{equation}
AB, \quad\quad B^\mathrm{T}A^\mathrm{T}, \quad\quad \left(B^\mathrm{T}A^\mathrm{T}\right)^\mathrm{T}, \quad\quad AC
\end{equation}
per Hand.
\item Definieren Sie die Begriffe der invertierbaren Matrix und der inversen Matrix.
\item Geben Sie die Formel zur Berechnung der Inversen einer $2 \times 2$ Matrix wieder.
\item Definieren Sie die Begriffe des Rangs und der Spur einer Matrix.
\item Geben Sie die Definition von Einheitsmatrix und Einheitsvektoren wieder.
\item Geben Sie die Definition einer Diagonalmatrix wieder.
\item Geben Sie die Definition einer symmetrischen Matrix wieder.
\item Geben Sie die Definition einer positiv-definiten Matrix wieder.

\end{enumerate}

```{r, echo = F, eval = F}
# Definitionen
A = matrix(c(1,2,3,
             4,5,6,
             3,2,0),
           nrow  = 3,
           byrow = TRUE)
B = matrix(c(1,2,2,
             1,3,1,
             2,0,0),
           nrow  = 3,
           byrow = TRUE)
C = matrix(c(1,3,2),
           nrow  = 3,
           byrow = TRUE)
print(A)
print(B)
print(C)
print(A %*% B)
print(t(B) %*% t(A))
print(t(t(B) %*% t(A)))
print(A %*% C)
```


<!-- Literatur -->
# Referenzen
