I have an list of coefficients that correspond to a polynomial expression, ie: [1,2,0]
corresponds to x^2 + 2x + 0
.
I would like to put an arbitrary length array of these coefficients into a lambda function.
Specifically, I am using mpmath and I have a list used for the polyval module that is:
polyval(ctx, coeffs, x, derivative=False)
Given coefficients and a number, polyval()
evaluates the polynomial.
And I need to use the findroot module that takes a one dimensional function, ie:
findroot(lambda x: x**3 + 2*x + 1, 2)
How can I construct a lambda function out of a list of coefficients?
Do you really need a lambda function? Using a "normal" function should be easier:
And using that
polyval()
function you mention, something like this should work:(For an appropriate
ctx
value)