changeset 29771:42dc5cf93f83

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 17 Jun 2021 18:26:29 +0200
parents 38bbe1a2828f (current diff) 4778b21b1386 (diff)
children fdbba73edde2
files scripts/linear-algebra/expm.m scripts/linear-algebra/isdiag.m scripts/linear-algebra/logm.m
diffstat 3 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/expm.m	Thu Jun 17 10:14:20 2021 -0400
+++ b/scripts/linear-algebra/expm.m	Thu Jun 17 18:26:29 2021 +0200
@@ -95,7 +95,7 @@
   elseif (isscalar (A))
     r = exp (A);
     return;
-  elseif (strfind (typeinfo (A), "diagonal matrix"))
+  elseif (isdiag (A))
     r = diag (exp (diag (A)));
     return;
   endif
@@ -155,6 +155,7 @@
 %!assert (expm (10), exp (10))
 %!assert (full (expm (eye (3))), expm (full (eye (3))))
 %!assert (full (expm (10*eye (3))), expm (full (10*eye (3))), 8*eps)
+%!assert (expm (zeros (3)), eye (3))
 
 ## Test input validation
 %!error <Invalid call> expm ()
--- a/scripts/linear-algebra/isdiag.m	Thu Jun 17 10:14:20 2021 -0400
+++ b/scripts/linear-algebra/isdiag.m	Thu Jun 17 18:26:29 2021 +0200
@@ -49,6 +49,7 @@
 
 %!assert (isdiag ("string"), false)
 %!assert (isdiag (zeros (2,2,2)), false)
+%!assert (isdiag (zeros (2)))
 %!assert (isdiag ([]))
 %!assert (isdiag (1))
 %!assert (isdiag ([1, 1]), false)
--- a/scripts/linear-algebra/logm.m	Thu Jun 17 10:14:20 2021 -0400
+++ b/scripts/linear-algebra/logm.m	Thu Jun 17 18:26:29 2021 +0200
@@ -63,7 +63,7 @@
   if (isscalar (A))
     s = log (A);
     return;
-  elseif (strfind (typeinfo (A), "diagonal matrix"))
+  elseif (isdiag (A))
     s = diag (log (diag (A)));
     return;
   endif
@@ -75,7 +75,8 @@
   endif
 
   eigv = diag (s);
-  real_neg_eigv = (real (eigv) < 0) & (imag (eigv) == 0);
+  tol = rows (A) * eps (max (abs (eigv)));
+  real_neg_eigv = (real (eigv) < -tol) & (imag (eigv) <= tol);
   if (any (real_neg_eigv))
     warning ("Octave:logm:non-principal",
              "logm: principal matrix logarithm is not defined for matrices with negative eigenvalues; computing non-principal logarithm");
@@ -187,6 +188,8 @@
 %!      -1.9769, -1.0922, -0.5831];
 %! warning ("off", "Octave:logm:non-principal", "local");
 %! assert (expm (logm (A)), A, 40*eps);
+%!assert (expm (logm (diag (ones (1, 3)))), diag (ones (1, 3)));
+%!assert (expm (logm (zeros (3))), zeros (3));
 
 ## Test input validation
 %!error <Invalid call> logm ()