Spurious complex eigenvalues caused by roundoff.

Hi everyone,
I found this piece of code in the MATLAB stats toolbox, file cmdscale.m
P = eye(n) - repmat(1/n,n,n);
B = P * (-.5 * D .* D) * P;
[V E] = eig((B+B')./2); % guard against spurious complex e-vals from roundoff
I understand that B+B'./2 is a common idiom of making a matrix symmetric, but I don't understand what dangers this is guarding against. Is it something to do with the computation of B? It's given that D is a symmetric matrix, so by definition B should be too. Perhaps very small values in the off-diagonal positions round to different values and this is a guard for that. What I don't understand is why this symmetric operation isn't itself susceptible to round-off errors. I don't have any intuition as to what's happening. Any comments or references to the literature would be most appreciated.
Thank you for your time,
Charles.

 Accepted Answer

Matrix multiplication, the "*" operator, does not promise symmetry on actual data that would algebraically deserve symmetry. This is because if you calculate the same algebraic value in any two different ways, even only very very different (like using F+H+G instead of F+G+H) then the two expressions might round differently. But for (B+B')/2, B+B' involves only single addition operations instead of a chain, Q+R vs R+Q, and for addition involving exactly two values, the round-off will always be the same no matter whether it is Q+R or R+Q. Therefore (B+B')/2 will be symmetric whereas B itself might not be.

More Answers (0)

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!