[SciPy-Dev] Add feature to approx_fprime

Jeffrey Manville jeffmanvillejr at gmail.com
Sat Sep 23 23:05:57 EDT 2017


Hello,

I have been using the approx_fprime and I noticed that the source code as
it is only uses the one sided numerical differentiation. I had to build my
own two sided one by copying and modifying the one sided code.

One sided: F'(x) = ( F(x+h) - F(x) ) / h                         aka Newton
method
Two sided:  F'(x) = ( F(x+h) - F(x-h) ) / (2*h)                aka
Symmetric method

The two sided method tends to be more accurate, but can be more
computationally expensive.

Is this something that would be good to add? I am newer to python and I
haven't contributed to open source yet, but it seems like a good fit.

I think it would be good to pass in a kwarg called method and set the
default to one sided, so no one's code breaks, but they can choose which
method to use.

Should I keep the decision logic at approx_fprime and have two separate
functions for the two methods?

Here's a wikipedia article on it
<https://en.wikipedia.org/wiki/Numerical_differentiation>
Here's a link to the source code
<https://github.com/scipy/scipy/blob/v0.19.1/scipy/optimize/optimize.py#L633-L688>

Cheers,

Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20170923/87340d02/attachment.html>


More information about the SciPy-Dev mailing list