Experiment -5:
Write a MATLAB program for Gram-Schmidt orthogonalization: to find orthogonal
basis vectors for the given set of vectors and plot the orthonormal vectors
A = input('Enter the elements of the matrix: ');
[n, k] = size(A);
U = zeros(n, k);
% First vector normalization
U(:,1) = A(:,1) / norm(A(:,1));
for i = 2:k
U(:,i) = A(:,i);
for j = 1:i-1
% Subtract projection onto previous orthonormal vectors
U(:,i) = U(:,i) - (U(:,j)' * A(:,i)) * U(:,j);
end
% Normalize the vector
U(:,i) = U(:,i) / norm(U(:,i));
end
disp('The orthonormalized matrix U is:');
disp(U);