1025
|
1 # Copyright (C) 1995 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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
904
|
18 |
1025
|
19 function y = polyvalm (c, x) |
|
20 |
|
21 # usage: polyvalm (c, x) |
|
22 # |
904
|
23 # Evaluate a polynomial in the matrix sense. |
561
|
24 # |
904
|
25 # In octave, a polynomial is represented by it's coefficients (arranged |
|
26 # in descending order). For example a vector c of length n+1 corresponds |
|
27 # to the following nth order polynomial |
561
|
28 # |
904
|
29 # p(x) = c(1) x^n + ... + c(n) x + c(n+1). |
561
|
30 # |
904
|
31 # polyvalm(c,X) will evaluate the polynomial in the matrix sense, i.e. matrix |
|
32 # multiplication is used instead of element by element multiplication as is |
|
33 # used in polyval. |
561
|
34 # |
904
|
35 # X must be a square matrix. |
|
36 # |
|
37 # SEE ALSO: polyval, poly, roots, conv, deconv, residue, filter, |
|
38 # polyderiv, polyinteg |
561
|
39 |
1025
|
40 # Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994. |
561
|
41 |
|
42 if(nargin != 2) |
1025
|
43 usage ("polyvalm (c, x)"); |
561
|
44 endif |
|
45 |
1025
|
46 if (is_matrix (c)) |
561
|
47 error("poly: first argument must be a vector."); |
|
48 endif |
|
49 |
1025
|
50 if(! is_square (x)) |
561
|
51 error("poly: second argument must be a square matrix."); |
|
52 endif |
|
53 |
|
54 [v, d] = eig(x); |
|
55 |
1025
|
56 y = v * diag (polyval (c, diag (d))) * v'; |
561
|
57 |
|
58 endfunction |