- publishing free software manuals
GNU Octave Manual Version 3
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
ISBN 095461206X
RRP £24.95 ($39.95)

Get a printed copy>>>

26.1 Evaluating Polynomials

The value of a polynomial represented by the vector c can be evaluated at the point x very easily, as the following example shows:

N = length(c)-1;
val = dot( x.^(N:-1:0), c );

While the above example shows how easy it is to compute the value of a polynomial, it isn't the most stable algorithm. With larger polynomials you should use more elegant algorithms, such as Horner's Method, which is exactly what the Octave function polyval does.

In the case where x is a square matrix, the polynomial given by c is still well-defined. As when x is a scalar the obvious implementation is easily expressed in Octave, but also in this case more elegant algorithms perform better. The polyvalm function provides such an algorithm.

Function File: polyval (c, x)
Evaluate a polynomial.

polyval (c, x) will evaluate the polynomial at the specified value of x.

If x is a vector or matrix, the polynomial is evaluated at each of the elements of x.

See also polyvalm, poly, roots, conv, deconv, residue, filter, polyderiv, polyinteg

Function File: polyvalm (c, x)
Evaluate a polynomial in the matrix sense.

polyvalm (c, x) will evaluate the polynomial in the matrix sense, i.e. matrix multiplication is used instead of element by element multiplication as is used in polyval.

The argument x must be a square matrix.

See also polyval, poly, roots, conv, deconv, residue, filter, polyderiv, and polyinteg

ISBN 095461206XGNU Octave Manual Version 3See the print edition