home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / f-schur.cc < prev    next >
C/C++ Source or Header  |  1995-01-03  |  3KB  |  151 lines

  1. // f-schur.cc                                           -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27.  
  28. #include "dbleSCHUR.h"
  29. #include "CmplxSCHUR.h"
  30.  
  31. #include "tree-const.h"
  32. #include "user-prefs.h"
  33. #include "utils.h"
  34. #include "error.h"
  35. #include "gripes.h"
  36. #include "help.h"
  37. #include "defun-dld.h"
  38.  
  39. DEFUN_DLD_BUILTIN ("schur", Fschur, Sschur, 3, 2,
  40.   "[U, S] = schur (A) or S = schur (A)\n\
  41. \n\
  42. or, for ordered Schur:\n\
  43. \n\
  44.   [U, S] = schur (A, TYPE) or S = schur (A, TYPE)\n\
  45. where TYPE is a string that begins with one of the following\n\
  46. characters:\n\
  47. \n\
  48.   A = continuous time poles\n\
  49.   D = discrete time poles\n\
  50.   U = unordered schur (default)")
  51. {
  52.   Octave_object retval;
  53.  
  54.   int nargin = args.length ();
  55.  
  56.   if (nargin < 1 || nargin > 2 || nargout > 2)
  57.     {
  58.       print_usage ("schur");
  59.       return retval;
  60.     }
  61.  
  62.   tree_constant arg = args(0);
  63.  
  64.   char *ord = "U";
  65.   if (nargin == 2)
  66.     {
  67.       ord = args(1).string_value ();
  68.  
  69.       if (error_state)
  70.     {
  71.       error ("schur: expecting string as second argument");
  72.       return retval;
  73.     }
  74.     }
  75.  
  76.   if (*ord != 'U' && *ord != 'A' && *ord != 'D'
  77.       && *ord != 'u' && *ord != 'a' && *ord != 'd')
  78.     {
  79.       warning ("schur: incorrect ordered schur argument `%c'", *ord);
  80.       return retval;
  81.     }
  82.  
  83.   int nr = arg.rows ();
  84.   int nc = arg.columns ();
  85.  
  86.   int arg_is_empty = empty_arg ("schur", nr, nc);
  87.  
  88.   if (arg_is_empty < 0)
  89.     return retval;
  90.   else if (arg_is_empty > 0)
  91.     return Octave_object (2, Matrix ());
  92.  
  93.   if (nr != nc)
  94.     {
  95.       gripe_square_matrix_required ("schur");
  96.       return retval;
  97.     }
  98.  
  99.   if (arg.is_real_type ())
  100.     {
  101.       Matrix tmp = arg.matrix_value ();
  102.  
  103.       if (! error_state)
  104.     {
  105.       SCHUR result (tmp,ord);
  106.  
  107.       if (nargout == 0 || nargout == 1)
  108.         {
  109.           retval(0) = result.schur_matrix ();
  110.         }
  111.       else
  112.         {
  113.           retval(1) = result.schur_matrix ();
  114.           retval(0) = result.unitary_matrix ();
  115.         }
  116.     }
  117.     }
  118.   else if (arg.is_complex_type ())
  119.     {
  120.       ComplexMatrix ctmp = arg.complex_matrix_value ();
  121.  
  122.       if (! error_state)
  123.     {
  124.       ComplexSCHUR result (ctmp,ord);
  125.  
  126.       if (nargout == 0 || nargout == 1)
  127.         {
  128.           retval(0) = result.schur_matrix ();
  129.         }
  130.       else
  131.         {
  132.           retval(1) = result.schur_matrix ();
  133.           retval(0) = result.unitary_matrix ();
  134.         }
  135.     }
  136.     }    
  137.   else
  138.     {
  139.       gripe_wrong_type_arg ("schur", arg);
  140.     }
  141.  
  142.   return retval; 
  143. }
  144.  
  145. /*
  146. ;;; Local Variables: ***
  147. ;;; mode: C++ ***
  148. ;;; page-delimiter: "^/\\*" ***
  149. ;;; End: ***
  150. */
  151.