Question
Implement QR factorization on the square matrix A with the Gram-Schmidt algorithm. Implement the factorization as a function in Python that only uses simple Numpy
Implement QR factorization on the square matrix A with the Gram-Schmidt algorithm. Implement the factorization as a function in Python that only uses simple Numpy functions, f.ex. numpy.dot and numpy.norm. Find the QR factorization of the matrix A = numpy.array([[1,2,0],[0,1,1],[1,0,1]]) with your code, and calculate the estimation error in the factorization, ||A - QR|| (it should be a number very close to zero).
Use the following code, and prove that it works on a couple of square matrices, both matrices with linearly dependent columns and linearly independent columns:
import numpy as np def qr(A): """ QR factorization input: square matrix A output: Q, R, b, where Q is a n x n matrix, with orthonormal column vectors, R n x n are the coefficients of the upper triangle matrix, so that A=QR b is True if the columns in A are linearly independent, else False """ n,k = A.shape # n is the number of rows, k is the number of columns assert(n == k) # A has to be a square matrix independent_columns = true # are the columns linearly independent? Q = np.zeros((n,n)) # starts with this initialized matrix R = np.zeros((n,n)) # triangle matrix, treated as complete matrix # enter code here # ... return Q,R,independent_columns
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started