Ramos
Ramos

Reputation: 9

How to use finite difference method for non-uniform grid in python?

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

Upvotes: 1

Views: 491

Answers (1)

mariolpantunes
mariolpantunes

Reputation: 1132

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.

Upvotes: 0

Related Questions