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} {} polyval (@var{c}, @var{x}) |
2311
|
22 ## Evaluate a polynomial. |
3426
|
23 ## |
3368
|
24 ## @code{polyval (@var{c}, @var{x})} will evaluate the polynomial at the |
|
25 ## specified value of @var{x}. |
3426
|
26 ## |
3368
|
27 ## If @var{x} is a vector or matrix, the polynomial is evaluated at each of |
|
28 ## the elements of @var{x}. |
5642
|
29 ## @seealso{polyvalm, poly, roots, conv, deconv, residue, filter, |
|
30 ## polyderiv, polyinteg} |
3368
|
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 = polyval (c, x) |
561
|
38 |
1025
|
39 if (nargin != 2) |
6046
|
40 print_usage (); |
561
|
41 endif |
|
42 |
4030
|
43 if (! (isvector (c) || isempty (c))) |
3458
|
44 error ("polyval: first argument must be a vector"); |
561
|
45 endif |
|
46 |
2716
|
47 if (isempty (x)) |
|
48 y = []; |
|
49 return; |
|
50 endif |
|
51 |
1025
|
52 if (length (c) == 0) |
561
|
53 y = c; |
|
54 return; |
|
55 endif |
|
56 |
1025
|
57 n = length (c); |
|
58 y = c (1) * ones (rows (x), columns (x)); |
561
|
59 for index = 2:n |
1025
|
60 y = c (index) + x .* y; |
561
|
61 endfor |
1025
|
62 |
561
|
63 endfunction |