[SciPy-user] determinants

Anne Archibald peridot.faceted@gmail....
Thu Sep 13 16:12:37 CDT 2007


On 13/09/2007, David Goldsmith <David.L.Goldsmith@noaa.gov> wrote:
> Anne Archibald wrote:
> > If you have problems with determinants becoming excessively large, you
> > may be able to circumvent them by computing the log of the
> > determinant. The easiest way to do this is to use LU decomposition:
> >
> > P,L,U = scipy.linalg.lu(M)
> > d = sum(log(abs(diag(L))))
> >
> > Of course you lose track of the sign doing this (P may be either an
> > even or odd permutation, though det should be reliable and efficient
> > on it).
> Of course, one can keep track of the sign by cumprod(sgn(diag(L))),
> yes?  (Sorry, I don't know the numpy functions for these off hand, but I
> assume they exist, yes?)

In my first draft I suggested this (prod(sign(diag(L)))), but
unfortunately P may contribute a factor of -1, so you have to extract
its determinant as well (unless there's some more clever way to get
the sign of a permutation matrix? some sum involving the positions of
the ones modulo 2 ought to do it, but it's been a while since I did
this kind of combinatorics).

Anne


More information about the SciPy-user mailing list