english translation started
This commit is contained in:
@@ -9,15 +9,15 @@ engine: julia
|
||||
using InteractiveUtils
|
||||
```
|
||||
|
||||
# Lineare Algebra in Julia
|
||||
# Linear Algebra in Julia
|
||||
|
||||
```{julia}
|
||||
using LinearAlgebra
|
||||
```
|
||||
|
||||
Das `LinearAlgebra`-Paket liefert unter anderem:
|
||||
The `LinearAlgebra` package provides among other things:
|
||||
|
||||
- zusätzliche Subtypen von `AbstractMatrix`: genauso verwendbar, wie andere Matrizen, z.B.
|
||||
- additional subtypes of `AbstractMatrix`: usable like other matrices, e.g.,
|
||||
|
||||
- `Tridiagonal`
|
||||
- `SymTridiagonal`
|
||||
@@ -25,26 +25,26 @@ Das `LinearAlgebra`-Paket liefert unter anderem:
|
||||
- `UpperTriangular`
|
||||
|
||||
|
||||
- zusätzliche/erweiterte Funktionen: `norm`, `opnorm`, `cond`, `inv`, `det`, `exp`, `tr`, `dot`, `cross`, ...
|
||||
- additional/extended functions: `norm`, `opnorm`, `cond`, `inv`, `det`, `exp`, `tr`, `dot`, `cross`, ...
|
||||
|
||||
- einen universellen Solver für lineare Gleichungssysteme: `\`
|
||||
- `x = A \ b` löst $A \mathbf{x}=\mathbf{b}$ durch geeignete Matrixfaktorisierung und Vorwärts/Rückwärtssubstition
|
||||
- a universal solver for systems of linear equations: `\`
|
||||
- `x = A \ b` solves $A \mathbf{x}=\mathbf{b}$ by appropriate matrix factorization and forward/backward substitution
|
||||
|
||||
- [Matrixfaktorisierungen](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#man-linalg-factorizations)
|
||||
- [Matrix factorizations](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#man-linalg-factorizations)
|
||||
- `LU`
|
||||
- `QR`
|
||||
- `Cholesky`
|
||||
- `SVD`
|
||||
- ...
|
||||
|
||||
- Berechnung von Eigenwerte/-vektoren
|
||||
- Computation of eigenvalues/eigenvectors
|
||||
|
||||
- `eigen`, `eigvals`, `eigvecs`
|
||||
|
||||
|
||||
- Zugriff auf BLAS/LAPACK-Funktionen
|
||||
- Access to BLAS/LAPACK functions
|
||||
|
||||
## Matrixtypen
|
||||
## Matrix Types
|
||||
|
||||
|
||||
|
||||
@@ -57,31 +57,31 @@ A = SymTridiagonal(fill(1.0, 4), fill(-0.3, 3))
|
||||
B = UpperTriangular(A)
|
||||
```
|
||||
|
||||
Diese Typen werden platzsparend gespeichert. Die üblichen Rechenoperationen sind implementiert:
|
||||
These types are stored space-efficiently. The usual arithmetic operations are implemented:
|
||||
|
||||
```{julia}
|
||||
A + B
|
||||
```
|
||||
|
||||
Lesende Indexzugriffe sind möglich,
|
||||
Read-only index access is possible,
|
||||
```{julia}
|
||||
A[1,4]
|
||||
```
|
||||
|
||||
schreibende nicht unbedingt:
|
||||
write operations not necessarily:
|
||||
```{julia}
|
||||
#| error: true
|
||||
A[1,3] = 17
|
||||
```
|
||||
|
||||
Die Umwandlung in eine 'normale' Matrix ist z.B. mit `collect()` möglich:
|
||||
Conversion to a 'normal' matrix is possible, for example, with `collect()`:
|
||||
```{julia}
|
||||
A2 = collect(A)
|
||||
```
|
||||
|
||||
### Die Einheitsmatrix `I`
|
||||
### The Identity Matrix `I`
|
||||
|
||||
`I` bezeichnet eine Einheitsmatrix (quadratisch, Diagonalelemente = 1, alle anderen = 0) in der jeweils erforderlichen Größe
|
||||
`I` denotes an identity matrix (square, diagonal elements = 1, all others = 0) of the respective required size
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -89,39 +89,39 @@ A + 4I
|
||||
```
|
||||
|
||||
|
||||
## Normen
|
||||
## Norms
|
||||
|
||||
Um Fragen wie Kondition oder Konvergenz eines Algorithmus studieren zu können, brauchen wir eine Metrik. Für lineare Räume ist es zweckmäßig, die Metrik über eine Norm zu definieren:
|
||||
To be able to study questions such as conditioning or convergence of an algorithm, we need a metric. For linear spaces, it is appropriate to define the metric via a norm:
|
||||
$$
|
||||
d(x,y) := ||x-y||
|
||||
$$
|
||||
|
||||
### $p$-Normen
|
||||
### $p$-Norms
|
||||
|
||||
Eine einfache Klasse von Normen im $ℝ^n$ sind die $p$-Normen
|
||||
A simple class of norms in $ℝ^n$ are the $p$-norms
|
||||
$$
|
||||
||\mathbf{x}||_p = \left(\sum |x_i|^p\right)^\frac{1}{p},
|
||||
$$
|
||||
die die die euklidische Norm $p=2$ verallgemeinern.
|
||||
which generalize the Euclidean norm $p=2$.
|
||||
|
||||
|
||||
:::{.callout-note}
|
||||
|
||||
## Die Max-Norm $p=\infty$
|
||||
## The Max-Norm $p=\infty$
|
||||
|
||||
Sei $x_{\text{max}}$ die _betragsmäßig_ größte Komponente von $\mathbf{x}\in ℝ^n$. Dann gilt stets
|
||||
Let $x_{\text{max}}$ be the _largest in absolute value_ component of $\mathbf{x}\in ℝ^n$. Then always
|
||||
$$ |x_{\text{max}}| \le ||\mathbf{x}||_p \le n^\frac{1}{p} |x_{\text{max}}|
|
||||
$$
|
||||
(Man betrachte einen Vektor, dessen Komponenten alle gleich $x_{\text{max}}$ sind bzw. einen Vektor, dessen Komponenten außer $x_{\text{max}}$ alle gleich Null sind.)
|
||||
(Consider a vector whose components are all equal to $x_{\text{max}}$ respectively a vector whose components are all equal to zero except $x_{\text{max}}$.)
|
||||
|
||||
Damit folgt
|
||||
Thus follows
|
||||
$$
|
||||
\lim_{p \rightarrow \infty} ||\mathbf{x}||_p = |x_{\text{max}}| =: ||\mathbf{x}||_\infty.
|
||||
$$
|
||||
:::
|
||||
|
||||
|
||||
In Julia definiert das `LinearAlgebra`-Paket eine Funktion `norm(v, p)`.
|
||||
In Julia, the `LinearAlgebra` package defines a function `norm(v, p)`.
|
||||
|
||||
```{julia}
|
||||
v = [3, 4]
|
||||
@@ -130,10 +130,10 @@ w = [-1, 2, 33.2]
|
||||
@show norm(v) norm(v, 2) norm(v, 1) norm(v, 4) norm(w, Inf);
|
||||
```
|
||||
|
||||
- Wenn das 2. Argument `p` fehlt, wird `p=2` gesetzt.
|
||||
- Das 2. Argument kann auch `Inf` (also $+\infty$) sein.
|
||||
- Das 1. Argument kann ein beliebiger Container voller Zahlen sein. Die Summe $\sum |x_i|^p$ erstreckt sich über *alle* Elemente des Containers.
|
||||
- Damit ist für eine Matrix `norm(A)` gleich der _Frobenius-Norm_ der Matrix `A`.
|
||||
- If the 2nd argument `p` is missing, `p=2` is set.
|
||||
- The 2nd argument can also be `Inf` (i.e., $+\infty$).
|
||||
- The 1st argument can be any container full of numbers. The sum $\sum |x_i|^p$ extends over *all* elements of the container.
|
||||
- Thus, for a matrix `norm(A)` is equal to the _Frobenius norm_ of the matrix `A`.
|
||||
|
||||
```{julia}
|
||||
A = [1 2 3
|
||||
@@ -144,12 +144,12 @@ norm(A) # Frobenius norm
|
||||
|
||||
|
||||
|
||||
Da Normen homogen unter Multiplikation mit Skalaren sind,
|
||||
$||\lambda \mathbf{x}|| = |\lambda|\cdot||\mathbf{x}||$, sind sie durch die Angabe der Einheitskugel vollständig bestimmt. Subadditivität der Norm (Dreiecksungleichung) ist äquivalent zur Konvexität der Einheitskugel
|
||||
(Code durch anklicken sichtbar).
|
||||
Since norms are homogeneous under multiplication with scalars,
|
||||
$||\lambda \mathbf{x}|| = |\lambda|\cdot||\mathbf{x}||$, they are completely determined by the specification of the unit ball. Subadditivity of the norm (triangle inequality) is equivalent to the convexity of the unit ball
|
||||
(code visible by clicking).
|
||||
```{julia}
|
||||
#| code-fold: true
|
||||
#| fig-cap: "Einheitskugeln im $ℝ^2$ für verschiedene $p$-Normen: $p$=0.8; 1; 1.5; 2; 3.001 und 1000"
|
||||
#| fig-cap: "Unit balls in $ℝ^2$ for different $p$-norms: $p$=0.8; 1; 1.5; 2; 3.001 and 1000"
|
||||
using Plots
|
||||
|
||||
colors=[:purple, :green, :red, :blue,:aqua, :black]
|
||||
@@ -163,35 +163,35 @@ for p ∈ (0.8, 1, 1.5, 2, 3.001, 1000)
|
||||
end
|
||||
fig1
|
||||
```
|
||||
Wie man sieht, muß $p\ge 1$ sein, damit die Einheitskugel konvex und $||.||_p$ eine Norm ist.
|
||||
As one can see, $p\ge 1$ must hold so that the unit ball is convex and $||.||_p$ is a norm.
|
||||
|
||||
Die Julia-Funktion `norm(v, p)` liefert allerdings für beliebige Parameter `p` ein Ergebnis.
|
||||
However, the Julia function `norm(v, p)` returns a result for arbitrary parameters `p`.
|
||||
|
||||
|
||||
### Induzierte Normen (Operatornormen)
|
||||
### Induced Norms (Operator Norms)
|
||||
|
||||
Matrizen $A$ repräsentieren lineare Abbildungen $\mathbf{v}\mapsto A\mathbf{v}$. Die von einer Vektornorm Induzierte Matrixnorm beantwortet die Frage:
|
||||
Matrices $A$ represent linear mappings $\mathbf{v}\mapsto A\mathbf{v}$. The matrix norm induced by a vector norm answers the question:
|
||||
|
||||
> _„Um welchen Faktor kann ein Vektor durch die Transformation $A$ maximal gestreckt werden?“_
|
||||
> _"By what factor can a vector be maximally stretched by the transformation $A$?"_
|
||||
|
||||
Auf Grund der Homogenität der Norm unter Multiplikation mit Skalaren reicht es aus, das Bild der Einheitskugel unter der Transformation $A$ zu betrachten.
|
||||
Due to the homogeneity of the norm under multiplication with scalars, it is sufficient to consider the image of the unit ball under the transformation $A$.
|
||||
|
||||
::: {.callout-tip}
|
||||
## Definition
|
||||
Sei $V$ ein Vektorraum mit einer Dimension $0<n<\infty$ und
|
||||
$A$ eine $n\times n$-Matrix. Dann ist
|
||||
Let $V$ be a vector space with dimension $0<n<\infty$ and
|
||||
$A$ an $n\times n$-matrix. Then
|
||||
$$
|
||||
||A||_p = \max_{||\mathbf{v}||_p=1} ||A\mathbf{v}||_p
|
||||
$$
|
||||
:::
|
||||
|
||||
Induzierte Normen lassen sich für allgemeines $p$ nur schwer berechnen. Ausnahmen sind die Fälle
|
||||
Induced norms can only be calculated with difficulty for general $p$. Exceptions are the cases
|
||||
|
||||
- $p=1$: Spaltensummennorm
|
||||
- $p=2$: Spektralnorm und
|
||||
- $p=\infty$: Zeilensummennorm
|
||||
- $p=1$: column sum norm
|
||||
- $p=2$: spectral norm and
|
||||
- $p=\infty$: row sum norm
|
||||
|
||||
Diese 3 Fälle sind in Julia in der Funktion `opnorm(A, p)` aus dem `LinearAlgebra`-Paket implementiert, wobei wieder `opnorm(A) = opnorm(A, 2)` gilt.
|
||||
These 3 cases are implemented in Julia in the function `opnorm(A, p)` from the `LinearAlgebra` package, where again `opnorm(A) = opnorm(A, 2)` holds.
|
||||
|
||||
```{julia}
|
||||
A = [ 0 1
|
||||
@@ -200,7 +200,7 @@ A = [ 0 1
|
||||
@show opnorm(A, 1) opnorm(A, Inf) opnorm(A, 2) opnorm(A);
|
||||
```
|
||||
|
||||
Das folgende Bild zeigt die Wirkung von $A$ auf Einheitsvektoren. Vektoren gleicher Farbe werden aufeinander abgebildet. (Code durch anklicken sichtbar):
|
||||
The following picture shows the effect of $A$ on unit vectors. Vectors of the same color are mapped onto each other. (Code visible by clicking):
|
||||
|
||||
```{julia}
|
||||
#| error: false
|
||||
@@ -214,12 +214,12 @@ CairoMakie.activate!(type = "svg")
|
||||
|
||||
```{julia}
|
||||
#| code-fold: true
|
||||
#| fig-cap: "Bild der Einheitskugel unter $v \\mapsto Av$ mit $||A||\\approx 2.088$"
|
||||
#| fig-cap: "Image of the unit ball under $v \\mapsto Av$ with $||A||\\approx 2.088$"
|
||||
|
||||
using CairoMakie
|
||||
|
||||
# Makie bug https://github.com/MakieOrg/Makie.jl/issues/3255
|
||||
# Würgaround https://github.com/MakieOrg/Makie.jl/issues/2607#issuecomment-1385816645
|
||||
# Workaround https://github.com/MakieOrg/Makie.jl/issues/2607#issuecomment-1385816645
|
||||
tri = BezierPath([
|
||||
MoveTo(Point2f(-0.5, -1)), LineTo(0, 0), LineTo(0.5, -1), ClosePath()
|
||||
])
|
||||
@@ -253,9 +253,9 @@ arrows!(fig2[1,3], x, y, Auv[1], Auv[2], arrowsize=10, arrowhead=tri, colormap=:
|
||||
fig2
|
||||
```
|
||||
|
||||
### Konditionszahl
|
||||
### Condition Number
|
||||
|
||||
Für p = 1, p = 2 (default) oder p = Inf liefert `cond(A,p)` die Konditionszahl in der $p$-Norm
|
||||
For p = 1, p = 2 (default) or p = Inf, `cond(A,p)` returns the condition number in the $p$-norm
|
||||
$$
|
||||
\text{cond}_p(A) = ||A||_p \cdot ||A^{-1}||_p
|
||||
$$
|
||||
@@ -264,37 +264,37 @@ $$
|
||||
@show cond(A, 1) cond(A, 2) cond(A) cond(A, Inf);
|
||||
```
|
||||
|
||||
## Matrixfaktorisierungen
|
||||
## Matrix Factorizations
|
||||
|
||||
Basisaufgaben der numerischen linearen Algebra:
|
||||
Basic tasks of numerical linear algebra:
|
||||
|
||||
- Löse ein lineares Gleichungssystem $A\mathbf{x} = \mathbf{b}$.
|
||||
- Falls keine Lösung existiert, finde die beste Annäherung, d.h., den Vektor $\mathbf{x}$, der $||A\mathbf{x} - \mathbf{b}||$ minimiert.
|
||||
- Finde Eigenwerte und Eigenvektoren $A\mathbf{x} = \lambda \mathbf{x}$ von $A$.
|
||||
- Solve a system of linear equations $A\mathbf{x} = \mathbf{b}$.
|
||||
- If no solution exists, find the best approximation, i.e., the vector $\mathbf{x}$ that minimizes $||A\mathbf{x} - \mathbf{b}||$.
|
||||
- Find eigenvalues and eigenvectors $A\mathbf{x} = \lambda \mathbf{x}$ of $A$.
|
||||
|
||||
Diese Aufgaben sind mit Matrixfaktorisierungen lösbar. Einige grundlegende Matrixfaktorisierungen:
|
||||
These tasks can be solved using matrix factorizations. Some fundamental matrix factorizations:
|
||||
|
||||
- **LU-Zerlegung** $A=L\cdot U$
|
||||
- faktorisiert eine Matrix als Produkt einer _lower_ und einer _upper_ Dreiecksmatrix
|
||||
- im Deutschen auch LR-Zerlegung (aber die Julia-Funktion heisst `lu()`)
|
||||
- geht (eventuell nach Zeilenvertauschung - Pivoting) immer
|
||||
- **Cholesky-Zerlegung** $A=L\cdot L^*$
|
||||
- die obere Dreiecksmatrix ist die konjugierte der unteren,
|
||||
- halber Aufwand im Vergleich zu LU
|
||||
- geht nur, wenn $A$ hermitesch und positiv definit ist
|
||||
- **QR-Zerlegung** $A=Q\cdot R$
|
||||
- zerlegt $A$ als Produkt einer orthogonalen (bzw. unitären im komplexen Fall) Matrix und einer oberen Dreiecksmatrix
|
||||
- $Q$ ist längenerhaltend (Drehungen und/oder Spiegelungen); die Stauchungen/Streckungen werden durch $R$ beschrieben
|
||||
- geht immer
|
||||
- **LU decomposition** $A=L\cdot U$
|
||||
- factorizes a matrix as a product of a _lower_ and an _upper_ triangular matrix
|
||||
- in German also called LR decomposition (but the Julia function is called `lu()`)
|
||||
- always works (possibly after row exchanges - pivoting)
|
||||
- **Cholesky decomposition** $A=L\cdot L^*$
|
||||
- the upper triangular matrix is the conjugate of the lower,
|
||||
- half the effort compared to LU
|
||||
- only works if $A$ is Hermitian and positive definite
|
||||
- **QR decomposition** $A=Q\cdot R$
|
||||
- decomposes $A$ as a product of an orthogonal (or unitary in the complex case) matrix and an upper triangular matrix
|
||||
- $Q$ is length-preserving (rotations and/or reflections); the scalings are described by $R$
|
||||
- always works
|
||||
- **SVD** _(Singular value decomposition)_: $A = U\cdot D \cdot V^*$
|
||||
- $U$ und $V$ sind orthogonal (bzw. unitär), $D$ ist eine Diagonalmatrix mit Einträgen in der Diagonale $σ_i\ge 0$, den sogenannten _Singulärwerten_ von $A$.
|
||||
- Jede lineare Transformation $\mathbf{v} \mapsto A\mathbf{v}$ läßt sich somit darstellen als eine Drehung (und/oder Spiegelung) $V^*$, gefolgt von einer reinen Skalierung $v_i \mapsto \sigma_i v_i$ und einer weitere Drehung $U$.
|
||||
- $U$ and $V$ are orthogonal (or unitary), $D$ is a diagonal matrix with entries on the diagonal $σ_i\ge 0$, the so-called _singular values_ of $A$.
|
||||
- Every linear transformation $\mathbf{v} \mapsto A\mathbf{v}$ can thus be represented as a rotation (and/or reflection) $V^*$, followed by a pure scaling $v_i \mapsto \sigma_i v_i$ and another rotation $U$.
|
||||
|
||||
|
||||
### LU-Faktorisierung
|
||||
### LU Factorization
|
||||
|
||||
LU-Faktorisierung ist Gauß-Elimination. Das Resultat der Gauß-Elimination ist die obere Dreiecksmatrix $U$. Die untere Dreiecksmatrix $L$ enthält Einsen auf der Diagonale und die nichtdiagonalen Einträge $l_{ij}$ sind gleich minus den Koeffizienten, mit denen im Gauß-Algorithmus Zeile $Z_j$ multipliziert und zu Zeile $Z_i$ addiert wird.
|
||||
Ein Beispiel:
|
||||
LU factorization is Gaussian elimination. The result of Gaussian elimination is the upper triangular matrix $U$. The lower triangular matrix $L$ contains ones on the diagonal and the non-diagonal entries $l_{ij}$ are equal to minus the coefficients by which row $Z_j$ is multiplied and added to row $Z_i$ in the Gaussian algorithm.
|
||||
An example:
|
||||
$$
|
||||
A=\left[
|
||||
\begin{array}{ccc}
|
||||
@@ -303,10 +303,10 @@ A=\left[
|
||||
-2 & 1 & 5
|
||||
\end{array}\right]
|
||||
~ \begin{array}{c}
|
||||
~\\
|
||||
Z_2 \mapsto Z_2 \mathbin{\color{red}-}\textcolor{red}{3} Z_1\\
|
||||
Z_3 \mapsto Z_3 + \textcolor{red}{2} Z_1
|
||||
\end{array} \quad \Longrightarrow\
|
||||
~\\
|
||||
Z_2 \mapsto Z_2 \mathbin{\color{red}-}\textcolor{red}{3} Z_1\\
|
||||
Z_3 \mapsto Z_3 + \textcolor{red}{2} Z_1
|
||||
\end{array} \quad \Longrightarrow\
|
||||
\left[
|
||||
\begin{array}{ccc}
|
||||
1 &2 &2 \\
|
||||
@@ -314,10 +314,10 @@ A=\left[
|
||||
& 5 & 9
|
||||
\end{array}\right]
|
||||
~ \begin{array}{c}
|
||||
~\\
|
||||
~\\
|
||||
Z_3 \mapsto Z_3 + \textcolor{red}{\frac{1}{2}} Z_2
|
||||
\end{array} \quad \Longrightarrow\
|
||||
~\\
|
||||
~\\
|
||||
Z_3 \mapsto Z_3 + \textcolor{red}{\frac{1}{2}} Z_2
|
||||
\end{array} \quad \Longrightarrow\
|
||||
\left[
|
||||
\begin{array}{ccc}
|
||||
1 &2 &2 \\
|
||||
@@ -342,11 +342,11 @@ A = \left[
|
||||
$$
|
||||
|
||||
|
||||
- Häufig in der Praxis: $A\mathbf{x}=\mathbf{b}$ muss für ein $A$ und viele rechte Seiten $\mathbf{b}$ gelöst werden.
|
||||
- Die Faktorisierung, deren Aufwand kubisch $\sim n^3$ mit der Matrixgröße $n$ wächst, muss nur einmal gemacht werden.
|
||||
- Der anschliessende Aufwand der Vorwärts/Rückwärtssubstition für jedes $\mathbf{b}$ ist nur noch quadratisch $\sim n^2$.
|
||||
- Often in practice: $A\mathbf{x}=\mathbf{b}$ must be solved for one $A$ and many right-hand sides $\mathbf{b}$.
|
||||
- The factorization, whose effort grows cubically $\sim n^3$ with the matrix size $n$, only needs to be done once.
|
||||
- The subsequent effort of forward/backward substitution for each $\mathbf{b}$ is only quadratically $\sim n^2$.
|
||||
|
||||
Das `LinearAlgebra`-Paket von Julia enthält zur Berechnung einer LU-Zerlegung die Funktion `lu(A, options)`:
|
||||
The `LinearAlgebra` package of Julia contains the function `lu(A, options)` for calculating an LU decomposition:
|
||||
```{julia}
|
||||
A = [ 1 2 2
|
||||
3 -4 4
|
||||
@@ -361,7 +361,7 @@ display(U)
|
||||
|
||||
#### Pivoting
|
||||
|
||||
Sehen wir uns einen Schritt der Gauß-Elimination an:
|
||||
Let's look at one step of Gaussian elimination:
|
||||
$$
|
||||
\left[
|
||||
\begin{array}{cccccc}
|
||||
@@ -375,37 +375,34 @@ $$
|
||||
\end{array}
|
||||
\right]
|
||||
$$
|
||||
Ziel ist es, als nächstes den Eintrag $a_{i+1,j}$ zum Verschwinden zu bringen, indem zur Zeile $Z_{i+1}$ ein geeignetes Vielfaches von Zeile $Z_i$ addiert wird. Das geht nur, wenn das _Pivotelement_ $\textcolor{red}{a_{ij}}$ nicht Null ist. Falls $\textcolor{red}{a_{ij}}=0$, müssen wir Zeilen vertauschen um dies zu beheben.
|
||||
The goal is to make the entry $a_{i+1,j}$ disappear by adding an appropriate multiple of row $Z_i$ to row $Z_{i+1}$. This only works if the _pivot element_ $\textcolor{red}{a_{ij}}$ is not zero. If $\textcolor{red}{a_{ij}}=0$, we must exchange rows to fix this.
|
||||
|
||||
Darüber hinaus ist die Kondition des Algorithmus am besten, wenn man bei jedem Schritt die Matrix so anordnet, dass das Pivotelement das betragsmäßig größte
|
||||
in der entsprechenden Spalte der noch zu bearbeitenden Umtermatrix ist. Beim (Zeilen-)Pivoting wird bei jedem Schritt durch Zeilenvertauschung sichergestellt, dass
|
||||
gilt:
|
||||
Furthermore, the conditioning of the algorithm is best if we arrange the matrix at each step so that the pivot element is the largest in absolute value in the corresponding column of the remaining submatrix. In (row) pivoting, rows are exchanged at each step to ensure that
|
||||
$$
|
||||
|\textcolor{red}{a_{ij}}|=\max_{k=i,...,m} |\textcolor{blue}{a_{kj}}|
|
||||
$$
|
||||
|
||||
#### LU in Julia
|
||||
|
||||
- Die Faktorisierungen in Julia geben ein spezielles Objekt zurück, das die Matrixfaktoren und weitere
|
||||
Informationen enthält.
|
||||
- Die Julia-Funktion `lu(A)` führt eine LU-Faktorisierung mit Pivoting durch.
|
||||
- The factorizations in Julia return a special object that contains the matrix factors and additional information.
|
||||
- The Julia function `lu(A)` performs an LU factorization with pivoting.
|
||||
|
||||
|
||||
```{julia}
|
||||
F = lu(A)
|
||||
typeof(F)
|
||||
```
|
||||
Elemente des Objekts:
|
||||
Elements of the object:
|
||||
```{julia}
|
||||
@show F.L F.U F.p;
|
||||
```
|
||||
Man kann auch gleich auf der linken Seite ein entsprechendes Tupel verwenden:
|
||||
One can also use an appropriate tuple on the left side:
|
||||
```{julia}
|
||||
L, U, p = lu(A);
|
||||
p
|
||||
```
|
||||
|
||||
Der Permutationsvektor zeigt an, wie die Zeilen der Matrix permutiert wurden. Es gilt: $$ L\cdot U = PA$$. Die Syntax der indirekten Indizierung erlaubt es, die Zeilenpermutation durch die Schreibweise `A[p,:]` anzuwenden:
|
||||
The permutation vector indicates how the rows of the matrix have been permuted. It holds: $$ L\cdot U = PA$$. The syntax of indirect indexing allows applying the row permutation with the notation `A[p,:]`:
|
||||
```{julia}
|
||||
display(A)
|
||||
display(A[p,:])
|
||||
@@ -413,28 +410,28 @@ display(L*U)
|
||||
```
|
||||
|
||||
|
||||
Die Vorwärts/Rückwärtssubstition mit einem `LU`- erledigt der Operator `\`:
|
||||
Forward/backward substitution with an `LU`-object is performed by the `\` operator:
|
||||
```{julia}
|
||||
b = [1, 2, 3]
|
||||
x = F \ b
|
||||
```
|
||||
Probe:
|
||||
Verification:
|
||||
```{julia}
|
||||
A * x - b
|
||||
```
|
||||
|
||||
In Julia verbirgt sich hinter dem `\`-Operator ein ziemlich universeller "matrix solver" und man kann ihn auch direkt anwenden:
|
||||
In Julia, the `\` operator hides a quite universal "matrix solver", and it can also be applied directly:
|
||||
```{julia}
|
||||
A \ b
|
||||
```
|
||||
Dabei wird implizit eine geeignete Faktorisierung durchgeführt, deren Ergebnis allerdings nicht abgespeichert.
|
||||
An appropriate factorization is performed implicitly, but its result is not saved.
|
||||
|
||||
|
||||
### QR-Zerlegung
|
||||
### QR Decomposition
|
||||
|
||||
|
||||
Die Funktion `qr()` liefert ein epezielles QR-Objekt zurück, das die Komponenten $Q$ und $R$ enthält. Die orthogonale (bzw. unitäre) Matrix $Q$ ist
|
||||
[in einer optimierten Form](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#man-linalg-abstractq) abgespeichert. Umwandlung in eine "normale" Matrix ist bei Bedarf wie immer mit `collect()` möglich.
|
||||
The function `qr()` returns a special QR object that contains the components $Q$ and $R$. The orthogonal (or unitary) matrix $Q$ is
|
||||
[in an optimized form](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#man-linalg-abstractq) stored. Conversion to a "normal" matrix is, as always, possible with `collect()` if needed.
|
||||
```{julia}
|
||||
F = qr(A)
|
||||
@show typeof(F) typeof(F.Q)
|
||||
@@ -442,11 +439,11 @@ display(collect(F.Q))
|
||||
display(F.R)
|
||||
```
|
||||
|
||||
### Passende Faktorisierung
|
||||
### Appropriate Factorization
|
||||
|
||||
|
||||
Die Funktion `factorize()` liefert eine dem Matrixtyp angepasste Form der Faktorisierung, siehe [Dokumentation](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.factorize) für Details.
|
||||
Wenn man Lösungen zu mehreren rechten Seiten $\mathbf{b_1}, \mathbf{b_2},...$ benötigt, sollte man die Faktorisierung nur einmal durchführen:
|
||||
The function `factorize()` returns a factorization form adapted to the matrix type, see [documentation](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.factorize) for details.
|
||||
If solutions for several right-hand sides $\mathbf{b_1}, \mathbf{b_2},...$ are needed, the factorization should only be performed once:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -462,4 +459,3 @@ Af \ [1, 2, 3]
|
||||
```{julia}
|
||||
Af \ [5, 7, 9]
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user