Solved Task 2b

This commit is contained in:
schrom01 2022-11-19 01:32:45 +01:00
parent 896480733c
commit 0074722ad3
1 changed files with 34 additions and 12 deletions

View File

@ -55,20 +55,42 @@ def Serie8_Aufg2(A):
if __name__ == '__main__':
A = np.array([[1, 2, -1], [4, -2, 6], [3, 1, 0]])
# Beispiel
# A = np.array([[1, 2, -1], [4, -2, 6], [3, 1, 0]])
# b = np.array([
# [9],
# [-4],
# [9]
# ])
# Example from Task 1
# A = np.array([
# [1, -2, 3],
# [-5, 4, 1],
# [2, -1, 3]
# ])
# b = np.array([
# [1],
# [9],
# [5]
# ])
A = np.array([
[1, -2, 3],
[-5, 4, 1],
[2, -1, 3]
])
b = np.array([
[1],
[9],
[5]
])
[Q,R]=Serie8_Aufg2(A)
n = len(b) - 1
QTb = Q.T @ b
result = [0 for i in range(n+1)]
row = n
while row >= 0:
value = QTb[row][0]
column = n
while column > row:
value -= R[row][column] * result[column]
column -= 1
value = value / R[row,row]
result[row] = value
row -= 1
print("\nQ:\n", Q)
print("\nR:\n", R)
print("\Result:\n", result)