This commit is contained in:
2025-11-29 11:13:50 +01:00
parent db3648bebb
commit 36cd2d662e
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import numpy as np
A = np.array([[8, 5, 2],
[5, 9, 1],
[4, 2, 7]], dtype=float)
b = np.array([19, 5, 34], dtype=float)
x_start = np.array([1, -1, 3], dtype=float)
x_exact = np.array([2, -1, 4], dtype=float)
D = np.diag(np.diag(A))
L_plus_U = A - D
inv_D = np.linalg.inv(D)
B_jacobi = -np.dot(inv_D, L_plus_U)
alpha = np.linalg.norm(B_jacobi, np.inf)
#german text
print(f"Alpha (Faktor von Kontraktion): {alpha}")
x_curr = x_start.copy()
print(f"x(0) = {x_curr}")
x_history = [x_curr.copy()]
for k in range(1, 4):
x_new = np.dot(inv_D, (b - np.dot(L_plus_U, x_curr)))
print(f"x({k}) = {x_new}")
x_history.append(x_new)
x_curr = x_new
print("-" * 30)
print(f"Näherungslösung x(3): {np.around(x_curr, 4)}")

View File

@@ -0,0 +1,25 @@
import numpy as np
A = np.array([[8, 5, 2], [5, 9, 1], [4, 2, 7]], dtype=float)
b = np.array([19, 5, 34], dtype=float)
x_k = np.array([1, -1, 3], dtype=float)
U = np.triu(A, 1)
DL = np.tril(A)
DL_inv = np.linalg.inv(DL)
print(f"Startvektor x(0): {np.around(x_k, 4)}")
x_history = [x_k.copy()]
for k in range(1, 4):
x_new = np.dot(DL_inv, (b - np.dot(U, x_k)))
x_history.append(x_new.copy())
x_k = x_new
print(f"x({k}): {np.around(x_k, 4)}")
x_1 = np.array([2.7500, -1.4167, 3.5714])
x_2 = np.array([2.1190, -1.0873, 3.9780])
x_3 = np.array([1.9861, -0.9945, 4.0049])
print("-" * 35)
print(f"Näherung x(3) (4 Dezimalstellen): {x_3}")