[Math] How to avoid complex value for square root of a symmetric matrix

linear algebramatrices

I want to find square root of a matrix $Z$ which is a symmetric matrix using eigen values. So I find the eigenvalues($A$) and eigenvectors($B$) of $Z$ and find $B A^{1/2} B$. But because of small negative eigenvalues (I think due to rounding errors), I get complex values for A^{1/2}. So square root of matrix $Z$ is complex. How to proceed in that case so that I get real square root (As far as I know square root of a symmetric matrix should be symmetric)?

Best Answer

This is a common problem. If you are certain that your matrix is supposed to be positive semidefinite, but is not so due only to small numerical errors, then you should simply replace any negative eigenvalues that you find in $A$ with zeros before computing $BA^{1/2}B$.

But again, you must be sure that your original matrix was supposed to be positive semidefinite before proceeding in this fashion. Use this as an opportunity to confirm that the preceding calculations are providing the expected results, so that your premise of positive semidefiniteness is valid.