561
|
1 function y = polyval(c,x) |
904
|
2 |
|
3 # Evaluate a polynomial. |
|
4 # |
|
5 # In octave, a polynomial is represented by it's coefficients (arranged |
|
6 # in descending order). For example a vector c of length n+1 corresponds |
|
7 # to the following nth order polynomial |
|
8 # |
|
9 # p(x) = c(1) x^n + ... + c(n) x + c(n+1). |
|
10 # |
|
11 # polyval(c,x) will evaluate the polynomial at the specified value of x. |
|
12 # |
|
13 # If x is a vector or matrix, the polynomial is evaluated at each of the |
|
14 # elements of x. |
|
15 # |
|
16 # SEE ALSO: polyvalm, poly, roots, conv, deconv, residue, filter, |
|
17 # polyderiv, polyinteg |
561
|
18 |
|
19 # Author: |
|
20 # Tony Richardson |
|
21 # amr@mpl.ucsd.edu |
|
22 # June 1994 |
|
23 |
|
24 if(nargin != 2) |
904
|
25 usage ("polyval(c,x)"); |
561
|
26 endif |
|
27 |
|
28 if(is_matrix(c)) |
|
29 error("poly: first argument must be a vector."); |
|
30 endif |
|
31 |
|
32 if(length(c) == 0) |
|
33 y = c; |
|
34 return; |
|
35 endif |
|
36 |
|
37 n = length(c); |
|
38 y = c(1)*ones(rows(x),columns(x)); |
|
39 for index = 2:n |
|
40 y = c(index) + x .* y; |
|
41 endfor |
|
42 endfunction |