Home > K25104 > LinearSystems > QR_Givens.m

QR_Givens

PURPOSE ^

Computes the QR factorization of A via Givens rotations

SYNOPSIS ^

function [ Q,R ] = QR_Givens( A )

DESCRIPTION ^

 Computes the QR factorization of A via Givens rotations
 Input arguments:
   A, matrix
 Output arguments:
   Q, square orthogonal matrix
   R, upper triangular

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005