Scipy Derivative

Viewed 9814

I have a question about the derivative function of Scipy. I used it last night and got some odd answers. I tried again this morning with some simple functions and got some right answers and some wrong. Here were my tests:

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

I checked the values of poly3 by hand and -2 = 17, 2 = 95, 0 = 15. So am I using the function wrong, or is there something wrong with the function. Thanks

Using: Python 2.7.3, IPython 0.12.1, Numpy 1.6.1, Scipy 0.9.0, Linux Mint 13

1 Answers
Related