diff --git a/Schenk_Brandenberger_S10_Aufg2.pdf b/Schenk_Brandenberger_S10_Aufg2.pdf new file mode 100644 index 0000000..2bf8375 Binary files /dev/null and b/Schenk_Brandenberger_S10_Aufg2.pdf differ diff --git a/Schenk_Brandenberger_S10_Aufg2.py b/Schenk_Brandenberger_S10_Aufg2.py new file mode 100644 index 0000000..545370c --- /dev/null +++ b/Schenk_Brandenberger_S10_Aufg2.py @@ -0,0 +1,21 @@ +import numpy as np + +print("*********Gauss Seidel*********") +def Gauss_Seidel(A,b,x,steps): + L = np.tril(A,k=-1) + D = np.diag(np.diag(A)) + R = np.triu(A, k=1) + print(np.linalg.norm(-np.linalg.inv(D+L) @ R,np.inf)) + for steps in range(steps): + x = -np.linalg.inv(D+L) @ R @ x + np.linalg.inv(D+L) @ b + return x + + +A = np.array([[8,5,2],[5,9,1],[4,2,7]]) +b = np.array([[19],[5],[34]]) +x = np.array([[1],[-1],[3]]) +steps = 3 +print(Gauss_Seidel(A,b,x,steps)) +print("Sum of vector:") +print(np.sum(Gauss_Seidel(A,b,x,steps))) +print(np.linalg.norm(Gauss_Seidel(A,b,x,3)-Gauss_Seidel(A,b,x,2),np.inf)) \ No newline at end of file