Home > K25104 > LinearSystems > Givens.m

Givens

PURPOSE ^

Applies one Givens rotation to place a zero in the (i,j)th entry of A.

SYNOPSIS ^

function [ B,G ] = Givens( A,i,j )

DESCRIPTION ^

 Applies one Givens rotation to place a zero in the (i,j)th entry of A.
 Input arguments:
   A, matrix
   i, row index
   j, column index, j<i
 Output arguments:
   G, Givens rotation
   B, B = G*A

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ B,G ] = Givens( A,i,j )
0002 % Applies one Givens rotation to place a zero in the (i,j)th entry of A.
0003 % Input arguments:
0004 %   A, matrix
0005 %   i, row index
0006 %   j, column index, j<i
0007 % Output arguments:
0008 %   G, Givens rotation
0009 %   B, B = G*A
0010 
0011 [n,~]=size(A); % finding the size of A
0012 if i>n || j>n || j>=i;   % Check that the indices specify an element of A
0013     error('element specified by the indices is not below the diagonal');
0014 end
0015 
0016 G=eye(n); B=A; % initializing G to the identity and B to A
0017 
0018 if abs(A(i,j))>0    % only apply Givens rotation if A(i,j) is non-zero
0019                     % otherwise no action necessary
0020     s=A(i,j)/sqrt(A(i,j)^2 + A(j,j)^2); % calculating the sine and cosine
0021     c=A(j,j)/sqrt(A(i,j)^2 + A(j,j)^2);  
0022     G(i,i)=c; G(j,j)=c;     % creating the relevant Givens rotation
0023     G(i,j)=-s; G(j,i)=s;
0024     B=G*B;      % applying the Givens rotation
0025 end
0026 
0027 end
0028

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