Python求导数

OωO好久没写博客了,忽然想起来就做下记录~使用Sympy和SciPy两种方式实现,简单的题目如下

已知f(x)=2(x**2)-3x
求f'(2)

Sympy

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

SciPy

from scipy.misc import derivative
def f(x): 
    return 2 * x ** 2 - 3 * x
u = derivative(f, 2)
print(u)

运行结果

5.0

就是很久没写博客了,划划水==

Last modification:August 12th, 2019 at 08:42 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment