changeset 26802:74e63d2fd0d0 stable

ordeig.m: Do not fail on 1x1 matrices (bug #55779); * ordeig.m (isquasitri): Special case 1x1 and 2x2 matrices and immediately return true. * ordeig.m: Add regression BIST test for 1x1 matrices.
author Sebastien Villemot <sebastien@debian.org>
date Mon, 25 Feb 2019 17:22:31 +0100
parents c2e6725987ce
children 41efc737ceb9
files scripts/linear-algebra/ordeig.m
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/ordeig.m	Mon Feb 25 23:08:27 2019 +0100
+++ b/scripts/linear-algebra/ordeig.m	Mon Feb 25 17:22:31 2019 +0100
@@ -99,10 +99,14 @@
 
 endfunction
 
-# Checks whether a matrix is quasi-triangular
+## Check whether a matrix is quasi-triangular
 function retval = isquasitri (A)
-  v = diag (A, -1) != 0;
-  retval = all (tril (A, -2)(:) == 0) && all (v(1:end-1) + v(2:end) < 2);
+  if (length (A) <= 2)
+    retval = true;
+  else
+    v = diag (A, -1) != 0;
+    retval = (all (tril (A, -2)(:) == 0) && all (v(1:end-1) + v(2:end) < 2));
+  endif
 endfunction
 
 
@@ -124,6 +128,11 @@
 %! lambda = ordeig (AA, BB);
 %! assert (lambda, diag (AA) ./ diag (BB));
 
+## Check trivial 1x1 case
+%!test <*55779>
+%! lambda = ordeig ([6], [2]);
+%! assert (lambda, 3);
+
 ## Test input validation
 %!error ordeig ()
 %!error ordeig (1,2,3)