Derivative of an array in python?

后端 未结 3 1082
刺人心
刺人心 2021-01-01 01:58

Currently I have two numpy arrays: x and y of the same size.

I would like to write a function (possibly calling numpy/scipy... functions if

3条回答
  •  感动是毒
    2021-01-01 02:17

    This is not a simple problem, but there are a lot of methods that have been devised to handle it. One simple solution is to used finite difference methods. The command `numpy.diff' uses finite differencing where you can specific the order of the derivative. Wikipedia also has a page that lists the needed finite differencing coefficients for different derivatives of different accuracies. If the numpy function doesn't do what you want.

    Depending on your application you can also use scipy.fftpack.diff which uses a completely different technique to do the same thing. Though your function needs a well defined Fourier transform.

    There are lots and lots and lots of variants (e.g. summation by parts finite differencing operators or operators designed to preserve known evolution constants in your system of equations) on both of the two ideas above. What you should do will depend a great deal on what the problem is that you are trying to solve.

    The good thing is that there a lot of work has been done on the field. The Wikipedia page for Numerical Differentiation has some resources (though it is focused on finite differencing techniques).

提交回复
热议问题