Gram Schmidt
Gram Schmidt
Yingwei Wang
Department of Mathematics, Purdue University, West Lafayette, IN
Some students said that they could not nd the so call gschmidt function
in the Matlab in their computers. So I wrote this routine to achieve the Gram-
Schmidt orthogonalization process in Matlab.
function [Q,R]=gschmidt(V)
% Input: V is an m by n matrix of full rank m<=n
% Output: an m-by-n upper triangular matrix R
% and an m-by-m unitary matrix Q so that A = Q*R.
[m,n]=size(V);
R=zeros(n);
R(1,1)=norm(V(:,1));
Q(:,1)=V(:,1)/R(1,1);
for k=2:n
R(1:k-1,k)=Q(:,1:k-1)*V(:,k);
Q(:,k)=V(:,k)-Q(:,1:k-1)*R(1:k-1,k);
R(k,k)=norm(Q(:,k));
Q(:,k)=Q(:,k)/R(k,k);
end