mirror of
https://gitlab.gwdg.de/j.hahn02/ws-numerik.git
synced 2026-03-01 19:32:42 +01:00
Remove llm
This commit is contained in:
297
GPT.md
297
GPT.md
@@ -1,297 +0,0 @@
|
||||
### Disclaimer ###
|
||||
|
||||
Dieser LLM-generierte Output dient als Überblick über die Aufgabe und zur Einschätzung, wie gut die aktuelle ChatGPT-Version solche Aufgaben bearbeiten kann.
|
||||
Er wird nicht direkt übernommen; die Inhalte werden selbst geprüft und eigenständig ausgearbeitet.
|
||||
|
||||
### Disclaimer ###
|
||||
|
||||
# Prompt to ChatGPT
|
||||
|
||||
Ausgefuehrt am 14.02.2026 auf der freien Version.
|
||||
|
||||
```prompt
|
||||
<Contents of ./TASK.md>
|
||||
|
||||
solve in detail
|
||||
```
|
||||
|
||||
# Answer from ChatGPT
|
||||
|
||||
## 1. Householder-Verfahren (kurz erklärt)
|
||||
|
||||
Die Householder-Transformation ist eine orthogonale Spiegelung, mit der man gezielt Einträge unterhalb der Diagonale auf 0 bringt.
|
||||
|
||||
Grundidee:
|
||||
|
||||
* Für eine Spalte (k) von (A) konstruiert man einen Vektor (v), sodass eine Spiegelung (H_k) den Teilvektor (a_k) auf eine Vielfache des Einheitsvektors (e_1) abbildet.
|
||||
* Die Householder-Matrix ist:
|
||||
[
|
||||
H_k = I - 2 \frac{v v^T}{v^T v}
|
||||
]
|
||||
* Diese ist orthogonal: (H_k^T = H_k^{-1})
|
||||
|
||||
Vorgehen:
|
||||
|
||||
1. Iteriere über Spalten (k = 1, ..., n)
|
||||
2. Bestimme (v), sodass alle Einträge unterhalb der Diagonale in Spalte (k) verschwinden
|
||||
3. Wende (H_k) auf die Restmatrix an
|
||||
|
||||
Am Ende:
|
||||
[
|
||||
Q = H_1 H_2 \cdots H_n,\quad S = Q^T A
|
||||
]
|
||||
|
||||
Eigenschaften:
|
||||
|
||||
* numerisch stabil
|
||||
* keine Verschlechterung der Kondition
|
||||
* besser als Gram-Schmidt in der Praxis
|
||||
|
||||
---
|
||||
|
||||
## 2. QS-Zerlegung für
|
||||
|
||||
[
|
||||
A =
|
||||
\begin{pmatrix}
|
||||
0 & 1 \
|
||||
0 & 0 \
|
||||
1 & 1
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
### Schritt 1: erste Spalte
|
||||
|
||||
[
|
||||
a_1 = (0,0,1)^T,\quad |a_1| = 1
|
||||
]
|
||||
|
||||
Wähle:
|
||||
[
|
||||
v = a_1 + |a_1| e_1 = (1,0,1)^T
|
||||
]
|
||||
|
||||
Norm:
|
||||
[
|
||||
v^T v = 2
|
||||
]
|
||||
|
||||
Householder:
|
||||
[
|
||||
H_1 = I - 2 \frac{vv^T}{v^T v} = I - \frac{vv^T}{1}
|
||||
]
|
||||
|
||||
[
|
||||
vv^T =
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 1 \
|
||||
0 & 0 & 0 \
|
||||
1 & 0 & 1
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
[
|
||||
H_1 =
|
||||
\begin{pmatrix}
|
||||
0 & 0 & -1 \
|
||||
0 & 1 & 0 \
|
||||
-1 & 0 & 0
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
### Schritt 2: transformiere A
|
||||
|
||||
[
|
||||
S = H_1 A =
|
||||
\begin{pmatrix}
|
||||
-1 & -1 \
|
||||
0 & 0 \
|
||||
0 & 1
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
### Schritt 3: zweite Spalte (unterer Block)
|
||||
|
||||
Betrachte:
|
||||
[
|
||||
(0,1)^T \Rightarrow v = (1,1)^T
|
||||
]
|
||||
|
||||
Ergibt:
|
||||
[
|
||||
H_2 =
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 \
|
||||
0 & 0 & -1 \
|
||||
0 & -1 & 0
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
### Endergebnis:
|
||||
|
||||
[
|
||||
S =
|
||||
\begin{pmatrix}
|
||||
-1 & -1 \
|
||||
0 & -1 \
|
||||
0 & 0
|
||||
\end{pmatrix}
|
||||
]
|
||||
|
||||
[
|
||||
Q = H_1 H_2
|
||||
]
|
||||
|
||||
---
|
||||
|
||||
## 3. Python-Implementierung (Householder)
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def householder_qs(A):
|
||||
A = A.astype(float)
|
||||
m, n = A.shape
|
||||
Q = np.eye(m)
|
||||
S = A.copy()
|
||||
|
||||
for k in range(n):
|
||||
# Teilvektor
|
||||
x = S[k:, k]
|
||||
|
||||
# Norm
|
||||
norm_x = np.linalg.norm(x)
|
||||
if norm_x == 0:
|
||||
continue
|
||||
|
||||
# Householder-Vektor
|
||||
e1 = np.zeros_like(x)
|
||||
e1[0] = 1
|
||||
v = x + np.sign(x[0]) * norm_x * e1
|
||||
v = v / np.linalg.norm(v)
|
||||
|
||||
# Transformation
|
||||
H_k = np.eye(m)
|
||||
H_k[k:, k:] -= 2.0 * np.outer(v, v)
|
||||
|
||||
# Anwenden
|
||||
S = H_k @ S
|
||||
Q = Q @ H_k
|
||||
|
||||
return Q, S
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Lösen von (Ax = b) mit QS
|
||||
|
||||
Gegeben:
|
||||
[
|
||||
A = QS
|
||||
]
|
||||
|
||||
Dann:
|
||||
[
|
||||
Ax = b \Rightarrow QSx = b
|
||||
]
|
||||
|
||||
Multipliziere mit (Q^T):
|
||||
[
|
||||
Sx = Q^T b
|
||||
]
|
||||
|
||||
Vorgehen:
|
||||
|
||||
1. (y = Q^T b)
|
||||
2. Löse (Sx = y) per Rückwärtseinsetzen
|
||||
|
||||
### Code:
|
||||
|
||||
```python
|
||||
def back_substitution(R, b):
|
||||
n = len(b)
|
||||
x = np.zeros(n)
|
||||
|
||||
for i in reversed(range(n)):
|
||||
x[i] = (b[i] - np.dot(R[i, i+1:], x[i+1:])) / R[i, i]
|
||||
|
||||
return x
|
||||
|
||||
|
||||
def solve_qs(A, b):
|
||||
Q, S = householder_qs(A)
|
||||
y = Q.T @ b
|
||||
x = back_substitution(S, y)
|
||||
return x
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Anwendung für (n=20, d=0.1)
|
||||
|
||||
### Matrix A erzeugen
|
||||
|
||||
```python
|
||||
def build_A(n, d):
|
||||
A = np.zeros((n, n))
|
||||
|
||||
for i in range(n):
|
||||
for j in range(n):
|
||||
if i == j:
|
||||
A[i, j] = d
|
||||
elif j == n-1:
|
||||
A[i, j] = 1
|
||||
elif i > j:
|
||||
A[i, j] = -1
|
||||
|
||||
return A
|
||||
```
|
||||
|
||||
### Vektor b
|
||||
|
||||
```python
|
||||
def build_b(n, d):
|
||||
b = np.zeros(n)
|
||||
for i in range(n):
|
||||
b[i] = (i+1) - n + d
|
||||
b[0] = 1 + d
|
||||
return b
|
||||
```
|
||||
|
||||
### Ausführung
|
||||
|
||||
```python
|
||||
n = 20
|
||||
d = 0.1
|
||||
|
||||
A = build_A(n, d)
|
||||
b = build_b(n, d)
|
||||
|
||||
x = solve_qs(A, b)
|
||||
print(x)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Erwartetes Verhalten
|
||||
|
||||
* Lösung existiert eindeutig (A regulär)
|
||||
* Numerisch stabil durch Householder
|
||||
* Ergebnis: Vektor (x \in \mathbb{R}^{20})
|
||||
|
||||
---
|
||||
|
||||
## Wichtige Punkte für die Abgabe
|
||||
|
||||
* Householder statt Gram-Schmidt → Stabilität
|
||||
* Kein Gebrauch von `np.linalg.qr`
|
||||
* Rückwärtseinsetzen selbst implementiert
|
||||
* Code kommentieren:
|
||||
|
||||
* Bedeutung von v
|
||||
* warum Norm + Vorzeichen
|
||||
* Struktur von H
|
||||
|
||||
---
|
||||
|
||||
Wenn gewünscht: kompakte Version für Portfolio (≤15.000 Zeichen) oder Latex-Ausarbeitung.
|
||||
Reference in New Issue
Block a user