diff --git a/Schenk_Brandenberger_S8_Aufg2.py b/Schenk_Brandenberger_S8_Aufg2.py index bfee133..73bb82f 100644 --- a/Schenk_Brandenberger_S8_Aufg2.py +++ b/Schenk_Brandenberger_S8_Aufg2.py @@ -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) \ No newline at end of file + print("\nR:\n", R) + print("\Result:\n", result) \ No newline at end of file