function [Q,R]=prob_4_4_27(A) % returns the QR factorization of the matrix A % % Written by: % -- % John L. Weatherwax 2006-10-23 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- [m,n]=size(A); Q=zeros(m,m); R=zeros(m,n); for k=1:n, R(k,k) = sqrt(sum(A(:,k).*A(:,k))); for i=1:m, Q(i,k) = A(i,k)/R(k,k); end for j=k+1:n, R(k,j) = sum(Q(:,k).*A(:,j)); end for i=1:m, A(i,j)=A(i,j)-Q(i,k)*R(k,j); end end