2
我需要以符號方式操作函數,然後對函數進行數值積分。如何在被積函數中正確使用我的表達式f。我如何正確使用lambdify?如果這甚至是明智的做法呢?非常感謝。Sympy:將符號表達式用作數字積分
from sympy import *
import scipy.integrate as integrate
r = symbols('r') #define symbol
f = diff(r*r) #carry out symbolic manipulation
def integrand(x): #define function to integrate
return lambdify(x, f) #swap variable x into f
result = integrate.quad(integrand, 0, 5) #integrate numerically
print(result)