Question: Implement a function, solve_qr(X, y), which uses the QR-based algorithm to estimate . To solve the triangular system, use Scipy's specialized function, available as sp.linalg.solve_triangular().

Implement a function, solve_qr(X, y), which uses the QR-based algorithm to estimate . To solve the triangular system, use Scipy's specialized function, available as sp.linalg.solve_triangular().

Implement a function, solve_qr(X, y), which uses the QR-based algorithm to estimate

import scipy.linalg def solve qr (X, y): ### YOUR CODE HERE theta-gr solve-qr (X, y) = print("Comparing your QR solution to the true solution:") show-Zvecs_tibble(theta-gr , theta-true, xname='theta-gr', yname='theta-true', error-True) print("Residual norm:") calc-residual-norm(x, y, theta. r ) # Test cell: solve gr test' import re try: del np.linalg.lstsq solve_qr (X, y) if re.findall( '1stsq, n.args [0]): raise n except NameError as n: print("*Double-check that you did not try to use lstsq)*" except AttributeError as a: if re.findall( '1stsq, a.args [0]) print("***Double-check that you did not try to use 1stsq). ***" raise a finally: np.linalg.lstsqSAVE_LSTSQ assert np.isclose (theta gr, theta_true).al1, "Your QR-based solution should be closer to the true solution." import scipy.linalg def solve qr (X, y): ### YOUR CODE HERE theta-gr solve-qr (X, y) = print("Comparing your QR solution to the true solution:") show-Zvecs_tibble(theta-gr , theta-true, xname='theta-gr', yname='theta-true', error-True) print("Residual norm:") calc-residual-norm(x, y, theta. r ) # Test cell: solve gr test' import re try: del np.linalg.lstsq solve_qr (X, y) if re.findall( '1stsq, n.args [0]): raise n except NameError as n: print("*Double-check that you did not try to use lstsq)*" except AttributeError as a: if re.findall( '1stsq, a.args [0]) print("***Double-check that you did not try to use 1stsq). ***" raise a finally: np.linalg.lstsqSAVE_LSTSQ assert np.isclose (theta gr, theta_true).al1, "Your QR-based solution should be closer to the true solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!