Your Task:
Assuming A ? R<sup>nxn</sup> is a Matrix object, and \(\vec{b} \in \mathbb{R}^n\) is a Vec object, implement a function solve_qr(A, b) that uses the QR-factorization of
A to compute and return the solution to the system Ax = \(\vec{b}\).
Hints:
1. If A = QR, then Ax = \(\vec{b}\) becomes QRx = \(\vec{b}\). What happens if we multiply both sides of the equation by the transpose of Q? i.e., What does
Q<sup>T</sup>QRx = Q<sup>T</sup>\(\vec{b}\) simplify to?
2. Part of your code for the solvers in CA #6 will come in handy.
In []: def solve_qr(A, b):
# todo
pass
In []: '''"TESTER CELL"""
A = Matrix([[2, -2, 18], [2, 1, 0], [1, 2, 0]])
x_true = Vec([3, 4, 5])
b = A * x_true
print("Expected:", x_true)
x = solve_qr(A, b)
print("Returned:", x)