function [x,v,At,bt]=TLS(A,b);
% TLS total least squares
%   [x,v,At,bt]=TLS(A,b) solves Ax~b by allowing changes in A and b.
     
C=[A,b];
[m,n]=size(C);
[U,Sigma,V]=svd(C,0);
v=V(:,n);
if v(n)==0
  disp('TLS Solution does not exist')
  x=[];
else
  x=-v(1:n-1)/v(n);
end
Ct=C-Sigma(n)*U(:,n)*V(:,n)';
At=Ct(:,1:n-1); bt=Ct(:,n);
