OωO好久没写博客了,忽然想起来就做下记录~使用Sympy和SciPy两种方式实现,简单的题目如下
已知f(x)=2(x**2)-3x
求f'(2)
from sympy import *
x = Symbol("x")
y = 2 * x ** 2 - 3 * x
dx = diff(y, x)
print(dx)
u = lambdify(x, dx)
print(u(2))
运行结果:
4*x - 3
5
from scipy.misc import derivative
def f(x):
return 2 * x ** 2 - 3 * x
u = derivative(f, 2)
print(u)
运行结果
5.0
就是很久没写博客了,划划水==