:@evalpoly
@evalpoly(z, c...)
Evaluate the polynomial $\sum_k c[k] z^{k1}$ for the
coefficients c[1]
, c[2]
, ...; that is, the coefficients are
given in ascending order by power of z
. This macro expands to
efficient inline code that uses either Horner's method or, for
complex z
, a more efficient Goertzellike algorithm.
Examples

Evaluate a polynomial using Horner's method:
julia> @evalpoly(2, 1, 2, 3) 17
In this example, the macro
@evalpoly
evaluates the polynomial1 + 2z + 3z^2
atz = 2
using Horner's method. The result is17
. 
Evaluate a polynomial with complex coefficients:
julia> @evalpoly(1 + 2im, 1 + 2im, 3 + 4im) 6 + 18im
The
@evalpoly
macro can handle complex coefficients as well. Here, it evaluates the polynomial(1 + 2im) + (1 + 2im)z + (3 + 4im)z^2
atz = 1 + 2im
, resulting in6 + 18im
. 
Evaluate a polynomial with different coefficient types:
julia> @evalpoly(0.5, 1//2, BigFloat(0.2)) 1.1
The
@evalpoly
macro can handle different coefficient types. In this example, it evaluates the polynomial1/2 + (1/2)z + 0.2z^2
atz = 0.5
, resulting in1.1
.  Evaluate a polynomial with variable number of coefficients:
julia> coefficients = [1, 2, 3, 4]; julia> @evalpoly(5, coefficients...) 586
The
@evalpoly
macro can accept a variable number of coefficients. Here, it evaluates the polynomial1 + 2z + 3z^2 + 4z^3
atz = 5
, resulting in586
.
Note that the macro @evalpoly
generates efficient inline code based on the input coefficients and the type of z
, whether it is real or complex.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.