Reputation: 1
I've been trying to vectorize this function for matlab:
function [Q,R]=gramSchmidtMod(A)
n=size(A,1);
R=zeros(n);
for j=1:n
R(j,j)=norm(A(:,j));
Q(:,j)=A(:,j)/R(j,j);
for i=j+1:n
R(j,i)=Q(:,j)'*A(:,i);
A(:,i)=A(:,i)-Q(:,j)*R(j,i);
end
end
end
i tried:
j=1:n
R(j,j)=norm(A(:,j));
Q(:,j)=A(:,j)/R(j,j);
i=j+1:n
R(j,i)=Q(:,j)'*A(:,i);
A(:,i)=A(:,i)-Q(:,j)*R(j,i);
but that doesn't respect the same order as it would when using two for loops. Can anyone help me out here ?
Upvotes: 0
Views: 134