时间:2021-07-01 10:21:17 帮助过:142人阅读
def func(coeff): sum='' for key in coeff: sum=sum+'+'+str(key)+'*'+'x'+'**'+str(coeff[key]) return sum[1:] from sympy import * from sympy.core.sympify import SympifyError expr = func({2:0,3:1,4:2,5:7}) x = Symbol("x") sexpr = sympify(expr) print diff(sexpr, x) print diff(sexpr, x).subs('x',3)
使用字典来完成这件事:
(2+3*x+4*x**2+7*x**3.7).diff(x).subs({x:3}).evalf()
希望本文所述对大家的Python程序设计有所帮助。