# HG changeset patch # User Jaroslav Hajek # Date 1280386283 -7200 # Node ID 1646bd8e37359029ff20f62e9b26170b2dbec703 # Parent b4ebfd6753218d23ecc73dfc0567e6a769ece6f6 special case diagonal matrices and scalars in expm diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-07-29 Jaroslav Hajek + + * linear-algebra/expm.m: Special-case scalars and diagonal matrices. + Suggested by M. Caliari. + 2010-07-26 Rik * linear-algebra/logm.m: Improve documentation string. Add GPL header. diff --git a/scripts/linear-algebra/expm.m b/scripts/linear-algebra/expm.m --- a/scripts/linear-algebra/expm.m +++ b/scripts/linear-algebra/expm.m @@ -76,6 +76,14 @@ error ("expm: input must be a square matrix"); endif + if (isscalar (a)) + r = exp (a); + return + elseif (strfind (typeinfo (a), "diagonal matrix")) + r = diag (exp (diag (a))); + return + endif + n = rows (a); ## Trace reduction. a(a == -Inf) = -realmax;