我对Scipy的衍生功能有疑问.我昨晚用它并得到了一些奇怪的答案.我今天早上再次尝试了一些简单的功能,得到了一些正确的答案和一些错误.这是我的测试:
In [1]: def poly1(x):
...: return x**2
In [3]: derivative(poly1, 0)
Out[3]: 0.0
In [4]: def poly2(x):
...: return (x-3)**2
In [6]: derivative(poly2, 3)
Out[6]: 0.0
In [8]: def sin1(x):
...: return sin(x)
In [14]: derivative(sin1, pi/2)
Out[14]: 5.5511151231257827e-17
In [15]: def poly3(x):
....: return 3*x**4 + 2*x**3 - 10*x**2 + 15*x - 2
In [19]: derivative(poly3, -2)
Out[19]: -39.0
In [20]: derivative(poly3, 2)
Out[20]: 121.0
In [22]: derivative(poly3, 0)
Out[22]: 17.0
Run Code Online (Sandbox Code Playgroud)
我用手检查了poly3的值,并且-2 = 17,2 = 95,0 = 15.所以我使用的函数是错误的,或者函数是否有问题.谢谢 …