[Numpy-discussion] Matrix square root

Konrad Hinsen hinsen at cnrs-orleans.fr
Thu Sep 4 08:48:44 EDT 2003


On Thursday 04 September 2003 16:42, Andrew Nesbit wrote:
> I need a function equivalent to Matlab's sqrtm, i.e., a square root
> for matrices.
>
> I constructed the following definition:
>
> def sqrtm(M):
>     (U,S,VT) = LinearAlgebra.singular_value_decomposition(M)
>     D = MLab.diag(sqrt(S))
>     return matrixmultiply(matrixmultiply(U,D),VT)
>
> but this technique only works for Hermitian, positive definite
> matrices.  The matrices I operate on don't necessarily satisfy that
> condition.

I'd use an eigenvalue decomposition, then take the square root of the 
eigenvalues, and then apply the diagonlization matrix in reverse. If you 
convert to eigenvalues to complex before taking the square root, this will 
work for non-positive-definite matrices, yielding a complex result.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------





More information about the NumPy-Discussion mailing list