Note: From the comments submitted below by other StackExchange users it appears that this apparent bug was fixed sometime after version 7.0.1.
I asked a vague variant of this question a few days ago, but now I will give a concrete example.
Floating point matrices with repeated eigenvalues often arise as the solutions to optimization problems.
The Mathematica functions MatrixPower
and Eigensystem
appear to have sporadic difficulty dealing with such matrices. (It is not clear to me whether this is because of numerical instability when trying to determine whether such matrices have nontrivial Jordan blocks, or if there is some other problem.) I have had to write my own routines for matrix power (and more generally for the functional calculus) to handle such cases, but maybe someone knows a quick fix.
In the notebook
I generated the following matrix by random search: (I'm using Mathematica 7.0.1 on 32-bit Windows)
{{0.461964, -0.314388, -0.138647, -2.23115*10^-6},
{-0.314388, 0.510134, -0.128432, -2.06676*10^-6},
{-0.138647, -0.128432, 0.744719, -9.11454*10^-7},
{-2.23115*10^-6, -2.06676*10^-6, -9.11454*10^-7, 0.801359}}
This matrix was defined by taking the average of a matrix and its transpose, so it is exactly self-adjoint. (I searched for it by finding rare matrices for which my usual code for inverting the Eigensystem
function acting on a Hermitian matrix failed.)
The list of eigenvalues
{0.801359, 0.801359, 0.801359, 0.1141}
has three repeated elements. All eigenvalues are positive, so Mathematica should have no trouble computing the unique positive semidefinite square root of this matrix.
However, using MatrixPower[%, 1/2]
, Mathematica reports that the square root is
{0.690223, -0.170008, -0.477225, 0.},
{-0.189862, 0.737704, -0.442063, 0.},
{-0.0837305, -0.0694507, 0.700234, 0.},
{-1.34742*10^-6, -1.11762*10^-6, -3.13724*10^-6, 0.895186}
This matrix is not even symmetric. Much worse, Mathematica computes the matrix product
(square root).(square root)
as
{{0.548644, -0.209616, -0.588406, 0.},
{-0.234095, 0.607187, -0.545053, 0.},
{-0.103238, -0.0856309, 0.560987, 0.},
{-1.66133*10^-6, -1.37799*10^-6, -3.86814*10^-6, 0.801359}},
which is nowhere near the original matrix:
{{0.461964, -0.314388, -0.138647, -2.23115*10^-6},
{-0.314388, 0.510134, -0.128432, -2.06676*10^-6},
{-0.138647, -0.128432, 0.744719, -9.11454*10^-7},
{-2.23115*10^-6, -2.06676*10^-6, -9.11454*10^-7, 0.801359}}
MatrixPower
must have changed between 8 and 9, as the handling of non positive definite matrices is now different. Maybe it was a bug and it has been fixed? $\endgroup$MatrixPower
is listed as "last updated in 6". $\endgroup$