function testlsq
% test for lsq computations
n=1000; m=5000;
xx=rand(n,1); H=rand(m,n); y=H*xx+randn(m,1);

tic, x=lsq1(H,y); t(1)=toc; v=y-H*x; s(1)=v'*v/(m-n);
tic, x=lsq2(H,y); t(2)=toc; v=y-H*x; s(2)=v'*v/(m-n);
tic, x=lsq3(H,y); t(3)=toc; v=y-H*x; s(3)=v'*v/(m-n);
tic, x=lsq4(H,y); t(4)=toc; v=y-H*x; s(4)=v'*v/(m-n);
tic, x=lsq5(H,y); t(5)=toc; v=y-H*x; s(5)=v'*v/(m-n);
tic, x=lsq6(H,y); t(6)=toc; v=y-H*x; s(6)=v'*v/(m-n);
tic, x=lsq7(H,y); t(7)=toc; v=y-H*x; s(7)=v'*v/(m-n);

for n=1:7, disp(sprintf('lsq%d : t=%6.3f s=%.15f',n,t(n),s(n))); end

function x=lsq1(H,y), x=H\y;
function x=lsq2(H,y), x=(H'*H)\(H'*y);
function x=lsq3(H,y), x=inv(H'*H)*(H'*y);
function x=lsq4(H,y), R=chol(H'*H); x=R\(R'\(H'*y));
function x=lsq5(H,y), [Q,R]=qr(H,0); x=R\(Q'*y);;
function x=lsq6(H,y), [U,D,V]=svd(H,0); x=V*(D\(U'*y));
function x=lsq7(H,y), x=pinv(H)*y;
