python求导数的方法。
例子:
#!/usr/bin/python
#求导数
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)
使用字典完成: