function [Q,R] = QRdec(A)

  n=rows(A); m=columns(A);
  Q = zeros(n,m); R = zeros(m,m);

  tiny = 1e-10;

  for j=1:m
    R(j,j) = sqrt(A(:,j).'*A(:,j));
    if R(j,j) < tiny, warning('determinant=0 ?'), endif
    Q(:,j) = A(:,j)/R(j,j);
    for k=j+1:m
      R(j,k) = A(:,k).'*Q(:,j);
      A(:,k) = A(:,k) - R(j,k)*Q(:,j);
    end
  end

endfunction
