maroba / findiff

Python package for numerical derivatives and partial differential equations in any number of dimensions.
MIT License
420 stars 60 forks source link

Reference for verifying coefficient computation algorithm #11

Closed mktitsworth closed 5 years ago

mktitsworth commented 5 years ago

Given that computing coefficients for finite difference calculations is a mature subject with many different algorithms, is there a reference for where the algorithm used in FinDiff came from so that it can validated against the specification?

maroba commented 5 years ago

Well, the determination of the coefficients is straight forward so that I didn't use a reference but pencil and paper instead. The resulting linear equation system is directly solved with the numpy.linalg package. The current implementation could potentially get inaccurate for very high derivatives or high accuracy orders, but I have checked the central/forward/backward coefficients against tabulated values up to 6th-derivative and 6th accuracy order and compared with symbolic calculations in Mathematica also for some higher orders and it this range seems to uncritical.

A different matter is the application of the differential operators. For reasonable derivative and accuracy orders, I have checked by comparing with given functions and their analytical derivatives and also verified that the scaling with the accuracy orders behaves correctly. However, for higher than n=6th derivatives the numerical errors from subtracting similar numbers and dividing by a spacing**n can get quite high. So far, I didn't care so much about that, since that use case seems to me quite exotic.