# Calculate full QR decomposition using modified Gram-Schmidt

I'm currently using the modified Gram-Schmidt algorithm to compute the QR decomposition of a matrix A (m x n). My current problem is that I need the full decomposition Q (m x m) instead of the thin one Q (m x n). Can somebody help me, what do I have to add to the algorithm to compute the full QR decomposition?.

import numpy as np

def gs_m(A):

m,n= A.shape
A= A.copy()
Q= np.zeros((m,n))
R= np.zeros((n,n))

for k in range(n):

R[k,k]= np.linalg.norm(A[:,k:k+1].reshape(-1),2)
Q[:,k:k+1]= A[:,k:k+1]/R[k,k]
R[k:k+1,k+1:n+1]= np.dot( Q[:,k:k+1].T, A[:,k+1:n+1] )
A[:,k+1:n+1]= A[:, k+1:n+1] - np.dot( Q[:,k:k+1], R[k:k+1,k+1:n+1])

return Q, R

-
Are you asking how to extend $Q$ so it is orthogonal? One possibility is after the above, run the modified GS algorithm on the basis vectors $e_1,...e_n$ and discard those that are already in the span. –  copper.hat Oct 3 '12 at 18:09