Python 无法将表达式转换为float(Can’t convert expression to float)
import sympy
import math
x = sympy.Symbol('x')
sympy.integrate(x**2 * math.exp(x) * math.cos(x), x)
TypeError: can’t convert expression to float
不能将sympy库创建的符号数学表达式与仅计算值的正常函数混合(如数学库中的那些.如果要创建符号表达式,则应始终使用sympy函数(sympy.exp, sympy.cos,sympy.log等):
x = sympy.Symbol('x')
sympy.integrate(x**2 * sympy.exp(x) * sympy.cos(x), x)