
A = hilb(10);
n = 10;

b = A * ones(n,1);

b = b + 1.e-9*randn(n,1);
A\b
ans =
   1.0e+04 *
    0.0001
   -0.0002
    0.0059
   -0.0529
    0.2542
   -0.7011
    1.1543
   -1.1184
    0.5887
   -0.1296


help pinv
 PINV   Pseudoinverse.
    X = PINV(A) produces a matrix X of the same dimensions
    as A' so that A*X*A = A, X*A*X = X and A*X and X*A
    are Hermitian. The computation is based on SVD(A) and any
    singular values less than a tolerance are treated as zero.
 
    PINV(A,TOL) treats all singular values of A that are less than TOL as
    zero. By default, TOL = max(size(A)) * eps(norm(A)).
 
    Class support for input A: 
       float: double, single
 
    See also RANK.

    Documentation for pinv
       doc pinv

    Other functions named pinv

       sym/pinv


x = pinv(A,1.e-08)*b
x =
    1.0000
    1.0003
    0.9979
    1.0046
    0.9982
    0.9965
    0.9997
    1.0031
    1.0028
    0.9969
x = pinv(A,1.e-07)*b
x =
    1.0000
    1.0003
    0.9979
    1.0046
    0.9982
    0.9965
    0.9997
    1.0031
    1.0028
    0.9969
x = pinv(A,1.e-04)*b
x =
    1.0000
    0.9991
    1.0032
    0.9977
    0.9972
    0.9998
    1.0023
    1.0030
    1.0010
    0.9965
x = pinv(A,1.e-02)*b
x =
    1.0150
    0.9233
    1.0130
    1.0541
    1.0587
    1.0428
    1.0163
    0.9846
    0.9509
    0.9169
x = pinv(A,1.e-02\4)*b
x =
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
x = pinv(A,1.e-04)*b
x =
    1.0000
    0.9991
    1.0032
    0.9977
    0.9972
    0.9998
    1.0023
    1.0030
    1.0010
    0.9965

trigtest1
addpath ../APPL/

mir
ans =
   256   256
.computing the T-SVD solution --- wait....
 done. 
close all



close all
mir
ans =
   256   256
.computing the T-SVD solution --- wait....
 done. 
close
close all





%% solve LS problem
A = randn(7,3);
b = randn(7,1);

%% min || b - Ax||_2  x?


x = (A'*A) \ (A'*b) 
x =
   -0.0452
   -0.3616
    0.2044
%% it is also the Pseudo inverse solution/







irDat
A =
     0     1     0     1     1     0     1     0
     0     1     1     0     0     0     0     1
     0     0     0     0     0     1     1     1
     0     0     0     1     0     0     0     0
     0     1     1     0     0     0     0     1
     1     0     0     1     0     0     0     0
     0     0     0     0     1     1     0     1
     0     0     1     1     0     0     0     1
     1     0     0     1     0     0     0     0
size(A)
ans =
     9     8



q
q =
         0
    0.7071
         0
         0
         0
         0
         0
    0.7071
         0
s0 = q'*A
s0 =
  Columns 1 through 5
         0    0.4082    0.8165    0.3162         0
  Columns 6 through 8
         0         0    0.6325





[U S V] = svd(A);

B = U(:,1:3)*S(1:3,1:3)*(V(:,1:3))'
B =
  Columns 1 through 5
    0.2561    0.2486    0.0738    0.4055    0.4687
   -0.0746    0.4758    0.6186    0.0830    0.0084
   -0.1214    0.1477   -0.0335    0.0243    0.4614
    0.2074    0.0424    0.0222    0.2131    0.0435
   -0.0746    0.4758    0.6186    0.0830    0.0084
    0.5578    0.0437   -0.0071    0.5411    0.0674
   -0.1214    0.1477   -0.0335    0.0243    0.4614
    0.1319    0.3593    0.4438    0.2412    0.0326
    0.5578    0.0437   -0.0071    0.5411    0.0674
  Columns 6 through 8
    0.3957    0.4687    0.3074
   -0.0169    0.0084    0.4684
    0.5272    0.4614    0.3075
   -0.0279    0.0435   -0.0005
   -0.0169    0.0084    0.4684
   -0.1214    0.0674   -0.0822
    0.5272    0.4614    0.3075
   -0.0483    0.0326    0.3132
   -0.1214    0.0674   -0.0822



B = B ./ sqrt( sum(A .^2, 1));
norm(B(:,4))
ans =
    0.9319
B = U(:,1:3)*S(1:3,1:3)*(V(:,1:3))'
B =
  Columns 1 through 5
    0.2561    0.2486    0.0738    0.4055    0.4687
   -0.0746    0.4758    0.6186    0.0830    0.0084
   -0.1214    0.1477   -0.0335    0.0243    0.4614
    0.2074    0.0424    0.0222    0.2131    0.0435
   -0.0746    0.4758    0.6186    0.0830    0.0084
    0.5578    0.0437   -0.0071    0.5411    0.0674
   -0.1214    0.1477   -0.0335    0.0243    0.4614
    0.1319    0.3593    0.4438    0.2412    0.0326
    0.5578    0.0437   -0.0071    0.5411    0.0674
  Columns 6 through 8
    0.3957    0.4687    0.3074
   -0.0169    0.0084    0.4684
    0.5272    0.4614    0.3075
   -0.0279    0.0435   -0.0005
   -0.0169    0.0084    0.4684
   -0.1214    0.0674   -0.0822
    0.5272    0.4614    0.3075
   -0.0483    0.0326    0.3132
   -0.1214    0.0674   -0.0822
B = U(:,1:3)*S(1:3,1:3)*(V(:,1:3))';

B = B ./ sqrt( sum(B .^2, 1));
norm(B(:,4))
ans =
    1.0000



s1 = q'*B
s1 =
  Columns 1 through 5
    0.0456    0.7094    0.7625    0.2460    0.0357
  Columns 6 through 8
   -0.0534    0.0357    0.6052
s0
s0 =
  Columns 1 through 5
         0    0.4082    0.8165    0.3162         0
  Columns 6 through 8
         0         0    0.6325
diary off
