[SciPy-Dev] Differentiate function

Evgeni Burovski evgeny.burovskiy at gmail.com
Mon Nov 7 11:52:09 EST 2016


Note that `approx_derivative` implements several finite-difference schemes,

https://github.com/scipy/scipy/blob/master/scipy/optimize/_numdiff.py#L179

For the moment, it's well hidden in scipy.optimize, but in the long
run the idea is to offer public functionality. So far the main issue
was the lack of bandwidth --- meaning if someone feels like working on
it, great!




On Mon, Nov 7, 2016 at 7:21 PM, Jonathan Stickel <jjstickel at gmail.com> wrote:
> Robert,
>
> I think, conceptually, something like this could be of interest in SciPy,
> but the devil is in the details. There are a lot of ways to implement finite
> differences; the code you shared provides the forward/backward finite
> differences with optional shift in the x positions. These are first-order
> accurate. Your interpolation of forward differences effectively results in
> the second-order accurate central-difference method.
>
> Evaluation of the endpoints is a bit more tricky; your approaches are simple
> but lack rigor (I am not sure of the accuracy). I know of formulas for
> second-order accurate endpoint finite differences for equally spaced x, but
> I am not sure about unequally spaced data (I am sure they exist but I
> haven't looked them up).
>
> So, should this functionality exist in SciPy, what methods should be
> implemented and made available? I think many of us (including myself) have
> implemented our own methods that are satisfactory for our particular needs,
> and no one has submitted general utility finite-differences functions that
> provides multiple methods with appropriate mathematical rigor. Such a
> function should also provide higher-order derivatives (at least second, but
> maybe up to fourth; or perhaps nth-order methods using a series formula).
>
> Also, the name should not be "diff" to avoid confusion with numpy.diff.
>
> Regards,
> Jonathan
>
>
>
>
> On 11/6/16 23:53 , Robert Rehammar wrote:
>>
>> Dear Pierre,
>>
>> Thank you for your reply. I am note fully aware of the difference
>> between numpy and scipy and also not a developer, but it seems to me
>> this function could fit in scipy where you often will want to
>> differentiate w.r.t. a particular variable. I am aware of diff, but it
>> is really a much more basic function. In many areas of science and
>> engineering is the sampling points of crucial importance, and having a
>> function giving you the appropriate sampling points can be very
>> important for accuracy.
>>
>> I have been missing this function several times my self, and hence the
>> reason why I submitted it here. Anyway, if there is no interest, I will
>> of course not peruse the matter further.
>>
>> Best,
>>
>> Robert
>>
>>
>> On 2016-11-05 22:53, Pierre de Buyl wrote:
>>>
>>> Dear Robert,
>>>
>>> On Thu, Nov 03, 2016 at 08:37:07PM +0100, Robert Rehammar wrote:
>>>>
>>>> Dear all,
>>>>
>>>> I implemented a simple function to differentiate an array which seems
>>>> other
>>>> people might like to have. It looks like:
>>>> def diff(f, x, retval = 'same'):
>>>> (...)
>>>>
>>>> What do you think about adding it to scipy?
>>>
>>> I am not a SciPy developer myself but I thought that I would point out
>>> NumPy's
>>> diff function. It does not go as far as your routine in terms of
>>> options but
>>> goes most of the way. It applies the differentiation to order 'n' as
>>> an option
>>> that is similar to the recursive application. Given this existing
>>> routine, the
>>> incentive to add another one might be low.
>>>
>>> Regards,
>>>
>>> Pierre
>>>
>>> _______________________________________________
>>> SciPy-Dev mailing list
>>> SciPy-Dev at scipy.org
>>> https://mail.scipy.org/mailman/listinfo/scipy-dev
>>
>>
>> _______________________________________________
>> SciPy-Dev mailing list
>> SciPy-Dev at scipy.org
>> https://mail.scipy.org/mailman/listinfo/scipy-dev
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-dev



More information about the SciPy-Dev mailing list