solved Task 2

This commit is contained in:
schrom01 2022-12-08 20:23:28 +01:00
parent b74e3eee77
commit 6c893b33b0
2 changed files with 21 additions and 0 deletions

Binary file not shown.

View File

@ -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))