comparison matrixcomp/gs_c.m @ 0:8f23314345f4 draft

Create local repository for matrix toolboxes. Step #0 done.
author Antonio Pino Robles <data.script93@gmail.com>
date Wed, 06 May 2015 14:56:53 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f23314345f4
1 function [Q, R] = gs_c(A)
2 %GS_C Classical Gram-Schmidt QR factorization.
3 % [Q, R] = GS_C(A) uses the classical Gram-Schmidt method to compute the
4 % factorization A = Q*R for m-by-n A of full rank,
5 % where Q is m-by-n with orthonormal columns and R is n-by-n.
6
7 % Reference:
8 % N. J. Higham, Accuracy and Stability of Numerical Algorithms,
9 % Second edition, Society for Industrial and Applied Mathematics,
10 % Philadelphia, PA, 2002; sec 19.8.
11
12 [m, n] = size(A);
13 Q = zeros(m,n);
14 R = zeros(n);
15
16 for j=1:n
17 R(1:j-1,j) = Q(:,1:j-1)'*A(:,j);
18 temp = A(:,j) - Q(:,1:j-1)*R(1:j-1,j);
19 R(j,j) = norm(temp);
20 Q(:,j) = temp/R(j,j);
21 end