Convert symbolic expressions to Python functions using SymPy
You want lambdify
.
f = lambdify(((x, y, z),), lagrange_eqs(a))
will give you a Python function f
that you can evaluate like f((1, 2, 3))
(for x=1
, y=2
, z=3
). I have made the arguments in a tuple so that it will work with scipy's fsolve
.
You can set the modules
flag to lambdify to determine where the exp
function will come from. For instance, to use numpy
, use lambdify((x, y, z), lagrange_eqs(a), modules="numpy")
. To use the standard library math library, use modules="math"
. By default, numpy is used if it is installed, otherwise math is used.