So I have an assignment to write algorithm code for Gram Schmidt process...I have done it in Matlab ,but when I run the code with input argument rand(some number), it gives me a result with variable ans... and some numbers in matrix... I want to create an output variable which won't be ans ,and can anyone see the code to tell me if it's okay? Thanks in advance,I would appreciate ur help..
% The vectors in A are independent BUT NOT YET orthonormal. Check A'*A. % If it is orthonormal, you should get strictly an identity matrix.
% number of vectors n = size( A, 2 );
% initialize output Q = zeros( n );
% turn every independent vector into a basis vector % (1) jth basis vector will be perpendicular to 1..j-1 previous found basis % (2) will be of length 1 (norm will be equal to 1) for j = 1 : n
u = A( :, j );
for i = 1 : j - 1
u = u - proj( Q(:,i), A(:,j) );
end
Q(:,j) = u ./ norm( u );
end
end
% projects a vector "a" on a direction "e" function p = proj( e, a )
% project "a" onto "e": (e' * a) / (e' * e) is the length (!) of "a" on "e" % multiplication by "e" is necessary to output the resulting vector which is % (colinear with "e") p = (e' * a) / (e' * e) .* e;
end