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 |
5053
|
30 ## |
3457
|
31 ## @seealso{polyval, poly, roots, conv, deconv, residue, filter, |
3649
|
32 ## polyderiv, and polyinteg} |
1025
|
33 |
3202
|
34 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
35 ## Created: June 1994 |
|
36 ## Adapted-By: jwe |
561
|
37 |
2312
|
38 function y = polyvalm (c, x) |
561
|
39 |
3085
|
40 if (nargin != 2) |
1025
|
41 usage ("polyvalm (c, x)"); |
561
|
42 endif |
|
43 |
4030
|
44 if (! (isvector (c) || isempty (c))) |
3458
|
45 error ("polyvalm: first argument must be a vector"); |
561
|
46 endif |
|
47 |
4030
|
48 if (! issquare (x)) |
3458
|
49 error ("polyvalm: second argument must be a square matrix"); |
561
|
50 endif |
|
51 |
2716
|
52 if (isempty (c)) |
|
53 y = []; |
|
54 return; |
|
55 endif |
|
56 |
|
57 [v, d] = eig (x); |
561
|
58 |
4030
|
59 if (issymmetric (x)) |
3085
|
60 y = v * diag (polyval (c, diag (d))) * v'; |
|
61 else |
|
62 y = v * (diag (polyval (c, diag (d))) / v); |
|
63 endif |
561
|
64 |
|
65 endfunction |