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} {} 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}. |
|
29 ## @end deftypefn |
5053
|
30 ## |
3457
|
31 ## @seealso{polyvalm, poly, roots, conv, deconv, residue, filter, |
|
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 = polyval (c, x) |
561
|
39 |
1025
|
40 if (nargin != 2) |
|
41 usage ("polyval (c, x)"); |
561
|
42 endif |
|
43 |
4030
|
44 if (! (isvector (c) || isempty (c))) |
3458
|
45 error ("polyval: first argument must be a vector"); |
561
|
46 endif |
|
47 |
2716
|
48 if (isempty (x)) |
|
49 y = []; |
|
50 return; |
|
51 endif |
|
52 |
1025
|
53 if (length (c) == 0) |
561
|
54 y = c; |
|
55 return; |
|
56 endif |
|
57 |
1025
|
58 n = length (c); |
|
59 y = c (1) * ones (rows (x), columns (x)); |
561
|
60 for index = 2:n |
1025
|
61 y = c (index) + x .* y; |
561
|
62 endfor |
1025
|
63 |
561
|
64 endfunction |