1

I have a function f = dp/de (variation in pressure as a function of variation in energy) and I would like to calculate this derivative with finite differences. I have a list for the p values ​​and a list for the e values. However, the grid formed by interpolating p with e is not uniform.

I tried, earlier, to calculate f as follows:

f.append((p[i+1] - p[i])/(e[i+1]- e[i]))

However, I need a better refinement at least in the first points.

How can I use finite difference method for non-uniform grids in python? Basically the grid has this format below (photo)

grid

Ramos
  • 9
  • 4
  • Could you use interpolation? Most of the scipy interpolators, e.g. [CubicSpline](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html#scipy.interpolate.CubicSpline) have a `derivative` method that allows you to calculate derivatives at any location. – Andrew Nelson Nov 18 '22 at 00:54

1 Answers1

0

I have a python library named uts (uneven time series) that allows one to compute the central differences for the first and second order. The code that matters is here.

mariolpantunes
  • 1,114
  • 2
  • 15
  • 28