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-hess.cc < prev    next >
C/C++ Source or Header  |  1995-01-03  |  3KB  |  126 lines

  1. // f-hess.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 "dbleHESS.h"
  29. #include "CmplxHESS.h"
  30.  
  31. #include "tree-const.h"
  32. #include "user-prefs.h"
  33. #include "error.h"
  34. #include "gripes.h"
  35. #include "utils.h"
  36. #include "help.h"
  37. #include "defun-dld.h"
  38.  
  39. DEFUN_DLD_BUILTIN ("hess", Fhess, Shess, 2, 2,
  40.   "[P, H] = hess (A) or H = hess (A): Hessenberg decomposition")
  41. {
  42.   Octave_object retval;
  43.  
  44.   int nargin = args.length ();
  45.  
  46.   if (nargin != 1 || nargout > 2)
  47.     {
  48.       print_usage ("hess");
  49.       return retval;
  50.     }
  51.  
  52.   tree_constant arg = args(0);
  53.  
  54.   int nr = arg.rows ();
  55.   int nc = arg.columns ();
  56.  
  57.   int arg_is_empty = empty_arg ("hess", nr, nc);
  58.  
  59.   if (arg_is_empty < 0)
  60.     return retval;
  61.   else if (arg_is_empty > 0)
  62.     return Octave_object (2, Matrix ());
  63.  
  64.   if (nr != nc)
  65.     {
  66.       gripe_square_matrix_required ("hess");
  67.       return retval;
  68.     }
  69.  
  70.   if (arg.is_real_type ())
  71.     {
  72.       Matrix tmp = arg.matrix_value ();
  73.  
  74.       if (! error_state)
  75.     {
  76.       HESS result (tmp);
  77.  
  78.       if (nargout == 0 || nargout == 1)
  79.         {
  80.           retval.resize (1);
  81.           retval(0) = result.hess_matrix ();
  82.         }
  83.       else
  84.         {
  85.           retval.resize (2);
  86.           retval(0) = result.unitary_hess_matrix ();
  87.           retval(1) = result.hess_matrix ();
  88.         }
  89.     }
  90.     }
  91.   else if (arg.is_complex_type ())
  92.     {
  93.       ComplexMatrix ctmp = arg.complex_matrix_value ();
  94.  
  95.       if (! error_state)
  96.     {
  97.       ComplexHESS result (ctmp);
  98.  
  99.       if (nargout == 0 || nargout == 1)
  100.         {
  101.           retval.resize (1);
  102.           retval(0) = result.hess_matrix ();
  103.         }
  104.       else
  105.         {
  106.           retval.resize (2);
  107.           retval(0) = result.unitary_hess_matrix ();
  108.           retval(1) = result.hess_matrix ();
  109.         }
  110.     }
  111.     }
  112.   else
  113.     {
  114.       gripe_wrong_type_arg ("hess", arg);
  115.     }
  116.  
  117.   return retval;
  118. }
  119.  
  120. /*
  121. ;;; Local Variables: ***
  122. ;;; mode: C++ ***
  123. ;;; page-delimiter: "^/\\*" ***
  124. ;;; End: ***
  125. */
  126.