% Script C5
% Checks out pTLS

clc
randn('seed',0)
m = 10; n = 5;
A = randn(m,n); b = randn(m,1);

display('Example 1. (Ordinary TLS)')
[x,E,r] = pTLS(A,b,0);
fprintf('\n x = [ %8.5f %8.5f %8.5f %8.5f %8.5f]\n',x)
fprintf('normE = %6.3f\n',norm(E,'fro'))
fprintf('normr = %6.3f\n',norm(r,2))
fprintf('resid = %10.3e\n\n',norm((A+E)*x - (b+r),2))

display('Example 2. (Ordinary LS)')
[x,E,r] = pTLS(A,b,5);
fprintf('\n x = [ %8.5f %8.5f %8.5f %8.5f %8.5f]\n',x)
fprintf('normE = %6.3f\n',norm(E,'fro'))
fprintf('normr = %6.3f\n\n',norm(r,2))
fprintf('resid = %10.3e\n\n',norm((A+E)*x - (b+r),2))

display('Example 3. (p = 2)')
[x,E,r] = pTLS(A,b,2);
fprintf('\n x = [ %8.5f %8.5f %8.5f %8.5f %8.5f]\n',x)
fprintf('normE = %6.3f\n',norm(E,'fro'))
fprintf('normr = %6.3f\n\n',norm(r,2))
fprintf('resid = %10.3e\n\n',norm((A+E)*x - (b+r),2))

format short
E = E