Bull3t 43v3r
Bull3t 43v3r

Reputation: 1

Matlab vectorization

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

Answers (1)

bla
bla

Reputation: 26069

Why won't you just use

[Q,R]=qr(A)

Upvotes: 1

Related Questions