home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / polynom / polyvalm.m < prev    next >
Text File  |  1999-12-24  |  2KB  |  66 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} polyvalm (@var{c}, @var{x})
  22. ## Evaluate a polynom in the matrix sense.
  23. ## 
  24. ## @code{polyvalm (@var{c}, @var{x})} will evaluate the polynom in the
  25. ## matrix sense, i.e. matrix multiplication is used instead of element by
  26. ## element multiplication as is used in polyval.
  27. ## 
  28. ## The argument @var{x} must be a square matrix.
  29. ## @end deftypefn
  30.  
  31. ## SEE ALSO: polyval, poly, roots, conv, deconv, residue, filter,
  32. ##           polyderv, polyintg
  33.  
  34. ## Author: Tony Richardson <arichard@stark.cc.oh.us>
  35. ## Created: June 1994
  36. ## Adapted-By: jwe
  37.  
  38. function y = polyvalm (c, x)
  39.  
  40.   if (nargin != 2)
  41.     usage ("polyvalm (c, x)");
  42.   endif
  43.  
  44.   if (! (is_vec (c) || isempty (c)))
  45.     error ("polyvalm: first argument must be a vector.");
  46.   endif
  47.  
  48.   if (! is_sqr (x))
  49.     error("polyvalm: second argument must be a square matrix.");
  50.   endif
  51.  
  52.   if (isempty (c))
  53.     y = [];
  54.     return;
  55.   endif
  56.  
  57.   [v, d] = eig (x);
  58.  
  59.   if (is_symm (x))
  60.     y = v * diag (polyval (c, diag (d))) * v';
  61.   else
  62.     y = v * (diag (polyval (c, diag (d))) / v);
  63.   endif
  64.  
  65. endfunction
  66.