📄 gramschmidt1.m
字号:
function [Q,R] = gramschmidt1(A)
%
% Compute the Gram-Schmidt orthogonalization of the
% columns of A, assuming nonzero columns of A
%
% function [Q,R] = gramschmidt1(A)
%
% A = input matrix to be factored (assuming nonzero columns)
%
% Q = orthogonal matrix
% R = upper triangular matrix such that A = QR
% Copyright 1999 by Todd K. Moon
[m,n] = size(A)
R = []; Q = []; % initialize
e1 = A(:,1); % first vector= first column of A
R(1,1) = norm(e1); % normalizing factor
Q = e1/R(1,1); % normalized vector
for k=2:n
R(1:k-1,k) = Q(:,1:k-1)'*A(:,k); % orthogonal projection coefficients
ek = A(:,k) - Q(:,1:k-1)*R(1:k-1,k); % orthogonal direction vector
R(k,k) = norm(ek); % new normalization
if(R(k,k))
ek = ek/R(k,k) % new orthogonal vector
end
Q = [Q ek];
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -