From: Konrad H. <hi...@cn...> - 2003-09-04 15:09:44
|
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) =3D LinearAlgebra.singular_value_decomposition(M) > D =3D 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=20 eigenvalues, and then apply the diagonlization matrix in reverse. If you=20 convert to eigenvalues to complex before taking the square root, this wil= l=20 work for non-positive-definite matrices, yielding a complex result. Konrad. --=20 -------------------------------------------------------------------------= ------ Konrad Hinsen | E-Mail: hi...@cn... 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 -------------------------------------------------------------------------= ------ |