Computes the QR factorization of A via Givens rotations Input arguments: A, matrix Output arguments: Q, square orthogonal matrix R, upper triangular
0001 function [ Q,R ] = QR_Givens( A ) 0002 % Computes the QR factorization of A via Givens rotations 0003 % Input arguments: 0004 % A, matrix 0005 % Output arguments: 0006 % Q, square orthogonal matrix 0007 % R, upper triangular 0008 0009 [n,~]=size(A); % finding the size of A 0010 0011 R=A; Q=eye(n); % initializing matrices Q,R 0012 0013 for j=1:n-1; 0014 for i=j+1:n; 0015 if R(i,j)~=0; % if the element is non-zero 0016 [R,G]=Givens(R,i,j); % call function which introduces a 0017 % zero in the (i,j)th entry of R using a Givens rotation. 0018 Q=Q*G'; % keep track of Q 0019 end 0020 end 0021 end 0022 0023 end 0024