Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyvalm.m @ 8334:70dd33450061
Update manual citation
author | David Bateman <dbateman@free.fr> |
---|---|
date | Tue, 18 Nov 2008 22:55:13 +0100 |
parents | 6f2d95255911 |
children | c174a1fc3fde |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2004, |
2 ## 2005, 2006, 2007 John W. Eaton | |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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. |
3457 | 29 ## @seealso{polyval, poly, roots, conv, deconv, residue, filter, |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
30 ## polyderiv, polyinteg} |
5642 | 31 ## @end deftypefn |
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) |
6046 | 40 print_usage (); |
561 | 41 endif |
42 | |
4030 | 43 if (! (isvector (c) || isempty (c))) |
3458 | 44 error ("polyvalm: first argument must be a vector"); |
561 | 45 endif |
46 | |
4030 | 47 if (! issquare (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 |
4030 | 58 if (issymmetric (x)) |
3085 | 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 | |
7411 | 65 |
66 %!assert(isempty (polyvalm ([], [1, 2; 3, 4]))); | |
67 | |
68 %!error polyvalm ([1, 1, 1], [1, 2; 3, 4; 5, 6]); | |
69 |