2
octave:1> A = [1 2 3; 4 5 6; 7 8 9]

octave:2> B = pinv (A)

octave:3> I = eye (size (A))
ans =

Diagonal Matrix

   1   0   0
   0   1   0
   0   0   1

octave:4> I2 = A * B
ans =

   0.83333   0.33333  -0.16667
   0.33333   0.33333   0.33333
  -0.16667   0.33333   0.83333

octave:5> A2 = A * I2
ans =

   1.00000   2.00000   3.00000
   4.00000   5.00000   6.00000
   7.00000   8.00000   9.00000

Why could the final Step 5 result in the perfect accuracy although the previous Step 4 in the unforgiving accuracy?

@EDIT

octave:6> format long

octave:7> I2
I2 =

   0.833333333333332   0.333333333333332  -0.166666666666666
   0.333333333333332   0.333333333333333   0.333333333333334
  -0.166666666666668   0.333333333333333   0.833333333333334

octave:8> A2
A2 =

   0.999999999999993   1.999999999999997   3.000000000000005
   3.999999999999982   4.999999999999992   6.000000000000014
   6.999999999999972   7.999999999999987   9.000000000000021
Community
  • 1
  • 1
sof
  • 9,113
  • 16
  • 57
  • 83
  • 1
    It's not perfect accuracy. You just can't see the non-zero decimal points because of your display format. – Suever Jul 22 '16 at 01:23
  • Both are much more precise than shown, but rounded for purposes of display. Both are also [likely inaccurate](http://stackoverflow.com/questions/588004/is-floating-point-math-broken), but with the details of the inaccuracy similarly hidden by display rounding. – Amadan Jul 22 '16 at 01:24

1 Answers1

2

The result does have errors, it's just that your display settings are such that everything is rounded to 4 decimal places (format short). If we change the display format (format long), we can see the errors:

format long

A * I2

%   0.999999999999990   1.999999999999998   3.000000000000007
%   3.999999999999978   4.999999999999993   6.000000000000017
%   6.999999999999965   7.999999999999987   9.000000000000027

Alternately, you can use num2str to show any arbitrary number of places after the decimal point.

% Show 32 places after the decimal point
num2str(A * I2, 32)

As for why A * pinv(A) * A is approximately equal to A, that is one of the defining properties of the Moore–Penrose pseudo-inverse computed by pinv.

enter image description here

Suever
  • 64,497
  • 14
  • 82
  • 101
  • Why is A2 derived from very inaccurate I2 still greatly accurate ? – sof Jul 22 '16 at 01:36
  • @sof Added a link describing the properties of the pseudo-inverse. What you are seeing is one of the 4 criteria of the pseudo-inverse. – Suever Jul 22 '16 at 01:50