MATLAB: Is the product of a matrix and its pseudo-inverse not symmetric in MATLAB 7.11 (R2011a)

MATLABmatrixpseudo inversepseudoinversesymmetric

The result of pinv(A)*A should lead to a symmetric matrix. The pseudo-inverse returned by MATLAB does not meet this property. I am calulating the pseudoinverse in my code below and can see that the results are symmetric.
load A.mat
X = pinv(A) * A % Result of pinv(A) * A (must be symmetric)
X =
1.0625 0 -0.0313
0 1.0000 -0.0156
0.0313 0.0156 0.9844
%%My calculation
[U, L, V] = svd(A);
L1 = L;
L1(1, 1) = 1 / L1(1, 1);
L1(2, 2) = 1 / L1(2, 2);
my_pinvA = V * L1 * U';
X = my_pinvA * A % Result of pinvA * A (must be symmetric)
X =
0.6667 -0.3333 -0.3333
-0.3333 0.6667 -0.3333
-0.3333 -0.3333 0.6667

Best Answer

The issue is related to floating point error of the results. Even though the product pinv(A)*A may not be exactly symmetric, but it is within the roundoff error of being symmetric.
As a test, try:
X = pinv(A);
S = A*X;
e = norm(S-S')/norm(S)
The relative error e should be roughly of size eps(X).
If it is important that S be exactly symmetric, it is recommended that you compute:
S = (S+S')/2;