Documentation |
Evaluate a polynomial at a point
This functionality does not run in MATLAB.
evalp(p, x = v, …) evalp(p, [x = v, …]) evalp(f, <vars>, x = v, …) evalp(f, <vars>, [x = v, …])
evalp(p, x = v) evaluates the polynomial p in the variable x at the point v.
An error occurs if x is not an indeterminate of p. The value v may be any object that could also be used as coefficient. The result is an element of the coefficient ring of p if p is univariate. If p is multivariate, the result is a polynomial in the remaining variables.
If several evaluation points are given, the evaluations take place in succession from left to right. Each evaluation follows the rules above.
For a polynomial p in the variables x1,x2,..., the syntax p(v1,v2,...) can be used instead of evalp(p, x1 = v1, x2 = v2, ...).
evalp(f, vars, x = v, ...) first converts the polynomial expression f to a polynomial with the variables given by vars. If no variables are given, they are searched for in f. See poly about details of the conversion. FAIL is returned if f cannot be converted to a polynomial. A successfully converted polynomial is evaluated as above. The result is converted to an expression.
Horner's rule is used to evaluate the polynomial. The evaluation of variables at the point 0 is most efficient and should take place first. After that, the remaining main variable should be evaluated first.
The result of evalp is not evaluated further. One may use eval to fully evaluate the result.
Instead of evalp(p, x1 = v1, x2 = v2, ...) one may also use the equivalent form evalp(p, [x1 = v1, x2 = v2, ...]).
evalp is used to evaluate the polynomial expression x^{2} + 2 x + 3 at the point x = a + 2. The form of the resulting expression reflects the fact that Horner's rule was used:
evalp(x^2 + 2*x + 3, x = a + 2)
evalp is used to evaluate a polynomial in the indeterminates x and y at the point x = 3. The result is a polynomial in the remaining indeterminate y:
p := poly(x^2 + x*y + 2, [x, y]): evalp(p, x = 3)
delete p:
Polynomials may be called like functions in order to evaluate all variables:
p := poly(x^2 + x*y, [x, y]): evalp(p, x = 3, y = 2) = p(3, 2)
delete p:
If not all variables are replaced by values, the result is a polynomial in the remaining variables:
evalp(poly(x*y*z + x^2 + y^2 + z^2, [x, y, z]), x = 1, y = 1)
The result of evalp is not evaluated further. We first define a polynomial p with coefficient a and then change the value of a. The change is not reflected by p, because polynomials do not evaluate their coefficients implicitly. One must map the function eval onto the coefficients in order to enforce evaluation:
p := poly(x^2 + a*y + 1, [x,y]): a := 2: p, mapcoeffs(p, eval)
If we use evalp to evaluate p at the point x = 1, the result is not fully evaluated. One must use eval to get fully evaluated coefficients:
r := evalp(p, x = 1): r, mapcoeffs(r, eval)
delete p, a, r:
p |
A polynomial of type DOM_POLY |
x |
An indeterminate |
v |
The value for x: an element of the coefficient ring of the polynomial |
f | |
vars |
A list of indeterminates of the polynomial: typically, identifiers or indexed identifiers |