diff scripts/linear-algebra/logm.m @ 14481:d2bffa78730e stable

Fix logm for complex matrix with real eigenvalues (bug #34893). * crsf2csf, zrsf2csf: Fix off-by-one error. * logm.m: Only truncate imaginary parts for real matrices. Add a test. * schur.cc: Add a test for rsf2csf.x
author Marco Caliari <marco.caliari@univr.it>
date Tue, 13 Mar 2012 11:56:35 +0100
parents 4d917a6a858b
children 5bd9e47e9277
line wrap: on
line diff
--- a/scripts/linear-algebra/logm.m	Sat Mar 17 23:24:10 2012 -0400
+++ b/scripts/linear-algebra/logm.m	Tue Mar 13 11:56:35 2012 +0100
@@ -104,7 +104,7 @@
   s = 2^k * u * s * u';
 
   ## Remove small complex values (O(eps)) which may have entered calculation
-  if (real_eig)
+  if (real_eig && isreal(A))
     s = real (s);
   endif
 
@@ -159,6 +159,7 @@
 %!assert(norm(logm([1 -1;0 1]) - [0 -1; 0 0]) < 1e-5);
 %!assert(norm(expm(logm([-1 2 ; 4 -1])) - [-1 2 ; 4 -1]) < 1e-5);
 %!assert(logm([1 -1 -1;0 1 -1; 0 0 1]), [0 -1 -1.5; 0 0 -1; 0 0 0], 1e-5);
+%!assert (logm (expm ([0 1i; -1i 0])), [0 1i; -1i 0], 10 * eps)
 
 %% Test input validation
 %!error logm ();