Projection of a vector $v$ onto the column space of a matrix $A$ is given by $AA^\dagger v$. From the definition of Moore-Penrose Inverse we know that $AA^\dagger v = (A^T)^\dagger A^T v $.

Below is the code for implementing the projection of a random vector onto the space of a random matrix. This is related to my other question Backward stable algorithm to get orthogonal projection onto the column space of a matrix. I didn't get an answer to that question.

I would like to know why is there a huge difference between the two methods of calculating the projection.

  % testingprojfrostackexchange
  M = 1400;
  N = 1300;
  r = 1;
  A = rand(M,N);
  u = rand(M,r);

  projLN = pinv(A')*(A'*u);%This is projection through Least Norm
  projLS = A*(pinv(A)*u);%This is projection through Least Square

  [Q R] = qr(A);
  Q = Q(:,1:N);
  z1 = Q*(Q'*u);%This is the actual projection

  display('(projection through QQT) - projLS');

  display('(projection through QQT) - projLN');


>> stackexchange
   (projection through QQT) - projLS

   ans =


   (projection through QQT) - projLN

   ans =


The actual projection which is given by $Q(:,1:N)Q(:,1:N)^T$, where $Q$ is from the Housholder decomposition of $A$. We get the projections from $AA^\dagger$ and $(A^T)^\dagger A^T$ and find that $AA^\dagger$ is much better when $A$ is a tall matrix.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.