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 |
2311
|
20 ## usage: polyvalm (c, x) |
|
21 ## |
|
22 ## Evaluate a polynomial in the matrix sense. |
|
23 ## |
|
24 ## In octave, a polynomial is represented by it's coefficients (arranged |
|
25 ## in descending order). For example a vector c of length n+1 corresponds |
|
26 ## to the following nth order polynomial |
|
27 ## |
|
28 ## p(x) = c(1) x^n + ... + c(n) x + c(n+1). |
|
29 ## |
|
30 ## polyvalm(c,X) will evaluate the polynomial in the matrix sense, i.e. matrix |
|
31 ## multiplication is used instead of element by element multiplication as is |
|
32 ## used in polyval. |
|
33 ## |
|
34 ## X must be a square matrix. |
|
35 ## |
|
36 ## SEE ALSO: polyval, poly, roots, conv, deconv, residue, filter, |
|
37 ## polyderiv, polyinteg |
1025
|
38 |
3202
|
39 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
40 ## Created: June 1994 |
|
41 ## Adapted-By: jwe |
561
|
42 |
2312
|
43 function y = polyvalm (c, x) |
561
|
44 |
3085
|
45 if (nargin != 2) |
1025
|
46 usage ("polyvalm (c, x)"); |
561
|
47 endif |
|
48 |
2716
|
49 if (! (is_vector (c) || isempty (c))) |
3085
|
50 error ("polyvalm: first argument must be a vector."); |
561
|
51 endif |
|
52 |
3085
|
53 if (! is_square (x)) |
|
54 error("polyvalm: second argument must be a square matrix."); |
561
|
55 endif |
|
56 |
2716
|
57 if (isempty (c)) |
|
58 y = []; |
|
59 return; |
|
60 endif |
|
61 |
|
62 [v, d] = eig (x); |
561
|
63 |
3085
|
64 if (is_symmetric (x)) |
|
65 y = v * diag (polyval (c, diag (d))) * v'; |
|
66 else |
|
67 y = v * (diag (polyval (c, diag (d))) / v); |
|
68 endif |
561
|
69 |
|
70 endfunction |