
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. Agree
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). If there is an interest in the function I can put a bit of more work into it. At it looks now, it is just a very fast hack that I did since I could not find it anywhere. Of course the things you point out should be
Jonathan, Please see below. On 2016-11-07 17:21, Jonathan Stickel wrote: treated more rigorously. For this function to be useful it is important that it can operate on unequally spaced grids since real-world data often is.
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).
Sure. The simplest way of doing that I guess is to do it recursively. But I can look into this and see what possibilities there are to do it more accurately. Since differentiating is a non-regulating operator, when working with real-world data, it is somethings of interest to also convolute with some windowing function to reduce noise. If the function should provide higher order derivatives, it might also need to be able to do that.
Also, the name should not be "diff" to avoid confusion with numpy.diff.
Yes of course. What do you propose? It could be differentiate, but it is a bit long. Some other possibilities derivative ndiff frac_diff fdiff Best, Robert
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,
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
On Thu, Nov 03, 2016 at 08:37:07PM +0100, Robert Rehammar wrote: 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@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev