octave: Evaluating Polynomials
28.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.
-- : Y = polyval (P, X)
-- : Y = polyval (P, X, [], MU)
-- : [Y, DY] = polyval (P, X, S)
-- : [Y, DY] = polyval (P, X, S, MU)
Evaluate the polynomial P at the specified values of X.
If X is a vector or matrix, the polynomial is evaluated for each of
the elements of X.
When MU is present, evaluate the polynomial for (X-MU(1))/MU(2).
In addition to evaluating the polynomial, the second output
represents the prediction interval, Y +/- DY, which contains at
least 50% of the future predictions. To calculate the prediction
interval, the structured variable S, originating from ‘polyfit’,
must be supplied.
DONTPRINTYET See also: polyvalm XREFpolyvalm, *notepolyaffine:
DONTPRINTYET See also: polyvalm XREFpolyvalm, polyaffine
XREFpolyaffine, polyfit XREFpolyfit, roots XREFroots,
poly XREFpoly.
-- : 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 used in ‘polyval’.
The argument X must be a square matrix.
DONTPRINTYET See also: polyval XREFpolyval, roots XREFroots, *noteDONTPRINTYET See also: polyval XREFpolyval, roots XREFroots,
poly XREFpoly.