In: Computer Science
I need a working MATLAB CODE for the Gram Schimdt process
Please give the code fast
Its urgent
The code must run on any matrix given
It should be a generic code
Dont answer any wrong code or else i will badly dislike
Here is the MATLAB CODE:
It is a generic code which runs for any matrix. We can change the value of n for it to work on any matrix order
clc;clear all
n=3; %%n=3 for 3x3 matrix
X=randi(n,n); %%Random integers matrix
Wans=CGS(X) %%Function call
function W=CGS(V) %%Function which implements the Gram-Schmidt
Algorithm for solution
[a b]=size(V);
for(i=1:a)
x(:,i)=V(:,i);
for(j=1:i-1)
x(:,i)=x(:,i)-(V(:,i)'*W(:,j))*W(:,j); %%Iterative formula
end
W(:,i)=x(:,i)/norm(x(:,i)); %%Normalisation
end
end