码迷,mamicode.com
首页 > 其他好文 > 详细

Gram Shimidt QR Factorization Matlab version

时间:2014-11-30 23:18:22      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   for   on   2014   log   cti   

function [Q,R] = gram_schmidt_qr(A)

% Formation: A = QR
% The implementation of QR Factorization(classical Gram-Schmidt method)
% Q is orthonormal basis for R(A)
% R is an upper-triangular matrix with positive diagonal entries.

% Author: Zhenlin Du(Johnsondu)
% Email:  qlduzhlin@126.com
% Time:   2014-11-27 22:00

A = double(A)
[m, n] = size(A);
Q = zeros(m, n);
R = zeros(n, n);

% for k = 1
u1 = A(:, 1);
Q(:, 1) = u1 / (sqrt(dot(u1, u1)));
R(1, 1) = (sqrt(dot(u1, u1)));

% for k > 1
for i = 2 : n
	% take column i
	u = A(:, i);  
	
    % compute R and u
	for j = 1: i - 1
		R(j, i) = dot(Q(:, j), u);
		u = u - R(j, i) * Q(:, j);
    end
    
    % get R(i, i)
	R(i, i) = (sqrt(dot(u, u)));
    % normalize
	u = u / R(i, i);
	Q(:, i) = u;
end

Gram Shimidt QR Factorization Matlab version

标签:blog   io   ar   os   for   on   2014   log   cti   

原文地址:http://blog.csdn.net/zone_programming/article/details/41630377

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!