changeset 14876:54a386f2ac4e

correcly compute Z for 3-output call to qz (bug #36728) * qz.cc (Fqz): Also compute Z if nargin == 3. Set third output if handling complex case. New test.
author John W. Eaton <jwe@octave.org>
date Wed, 18 Jul 2012 15:37:36 -0400
parents c2dbdeaa25df
children 02952657182e 4c8ddf57fcda 504fec921af5
files src/DLD-FUNCTIONS/qz.cc
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/qz.cc	Tue Jul 17 13:34:19 2012 -0700
+++ b/src/DLD-FUNCTIONS/qz.cc	Wed Jul 18 15:37:36 2012 -0400
@@ -534,7 +534,7 @@
   ComplexMatrix CQ(nn,nn), CZ(nn,nn), CVR(nn,nn), CVL(nn,nn);
   octave_idx_type ilo, ihi, info;
   char compq = (nargout >= 3 ? 'V' : 'N');
-  char compz = (nargout >= 4 ? 'V' : 'N');
+  char compz = ((nargout >= 4 || nargin == 3)? 'V' : 'N');
 
   // Initialize Q, Z to identity if we need either of them.
   if (compq == 'V' || compz == 'V')
@@ -1182,7 +1182,12 @@
 
     case 3:
       if (nargin == 3)
-        retval(2) = CZ;
+        {
+          if (complex_case)
+            retval(2) = CZ;
+          else
+            retval(2) = ZZ;
+        }
       else
         {
           if (complex_case)
@@ -1264,5 +1269,10 @@
 %! assert (q * a * z, aa, norm (aa) * 1e-14);
 %! assert (q * b * z, bb, norm (bb) * 1e-14);
 
-## FIXME: Still need a test for third form of calling qz
+%!test
+%! A = [0, 0, -1, 0; 1, 0, 0, 0; -1, 0, -2, -1; 0, -1, 1, 0];
+%! B = [0, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1];
+%! [AA, BB, Q, Z1] = qz (A, B);
+%! [AA, BB, Z2] = qz (A, B, '-');
+%! assert (Z1, Z2);
 */