Sympy: Using A Symbolic Expression As A Numerical Integrand
I need to manipulate a function symbolically, and then numerically integrate the function. How do I correctly use my expression f in the integrand function. How do I use lambdify c
Solution 1:
lambdify
returns a function object, there is no need to use a wrapper function. Also note that the first argument of lambdify
should be a tuple of variables representing sympy
symbols (in this case, r
) that are included in the sympy expression (in this case, f_sym
) provided as its second argument.
import sympy as sp
from scipy.integrate import quad
r = sp.symbols('r')
f_sym = sp.diff(r*r, r)
f_lam = sp.lambdify(r, f_sym)
result = quad(f_lam, 0, 5)
print(result)
(25.0, 2.7755575615628914e-13)
Post a Comment for "Sympy: Using A Symbolic Expression As A Numerical Integrand"