2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
904
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} polyvalm (@var{c}, @var{x}) |
2311
|
22 ## Evaluate a polynomial in the matrix sense. |
3426
|
23 ## |
3368
|
24 ## @code{polyvalm (@var{c}, @var{x})} will evaluate the polynomial in the |
|
25 ## matrix sense, i.e. matrix multiplication is used instead of element by |
|
26 ## element multiplication as is used in polyval. |
3426
|
27 ## |
3368
|
28 ## The argument @var{x} must be a square matrix. |
|
29 ## @end deftypefn |
3457
|
30 ## @seealso{polyval, poly, roots, conv, deconv, residue, filter, |
3649
|
31 ## polyderiv, and polyinteg} |
1025
|
32 |
3202
|
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
34 ## Created: June 1994 |
|
35 ## Adapted-By: jwe |
561
|
36 |
2312
|
37 function y = polyvalm (c, x) |
561
|
38 |
3085
|
39 if (nargin != 2) |
1025
|
40 usage ("polyvalm (c, x)"); |
561
|
41 endif |
|
42 |
2716
|
43 if (! (is_vector (c) || isempty (c))) |
3458
|
44 error ("polyvalm: first argument must be a vector"); |
561
|
45 endif |
|
46 |
3085
|
47 if (! is_square (x)) |
3458
|
48 error ("polyvalm: second argument must be a square matrix"); |
561
|
49 endif |
|
50 |
2716
|
51 if (isempty (c)) |
|
52 y = []; |
|
53 return; |
|
54 endif |
|
55 |
|
56 [v, d] = eig (x); |
561
|
57 |
3085
|
58 if (is_symmetric (x)) |
|
59 y = v * diag (polyval (c, diag (d))) * v'; |
|
60 else |
|
61 y = v * (diag (polyval (c, diag (d))) / v); |
|
62 endif |
561
|
63 |
|
64 endfunction |