How to calculate derivative by Lagrange interpolation

hi All,

is there a pkg to calculate derivative at untabulated points using langrange interpolation?


does it have to be lagrange interpolation? That’s not necessarily a stable method, for example there’s Runge’s phenomenon. Runge's phenomenon - Wikipedia

I’d suspect the combination of Polynomials.jl and SpecialPolynomials.jl could help.

I’m not sure what you mean by “untabulated,” but ApproxFun may be of help. Especially look at the documentation FAQ about values on predefined grids.

1 Like

The numerically stable version of Lagrange interpolation is barycentric interpolation, which is implemented here: GitHub - dawbarton/BarycentricInterpolation.jl: A Julia implementation of Barycentric interpolation and differentiation formulae …always use this rather than Lagrange.

Beware that if you choose the interpolation points unwisely (e.g. equally spaced or randomly) then at high polynomial degrees you are likely to hit Runge phenomena with any polynomial interpolation method. The main ways around this is to (a) choose the points well, e.g. at Chebyshev nodes or (b) least-square fit to a lower-degree polynomial (e.g. fit to a degree-10 polynomial with 100 points). GitHub - stevengj/FastChebInterp.jl: fast multidimensional Chebyshev interpolation and regression in Julia can do both of those things for you, and there are other packages as well (e.g. ApproxFun can do it, but is really oriented towards other tasks than interpolating data).


It has an implementation of the Lagrange interpolation in Barycentric form (IIRC) and it specializes the derivative calculation as well.

1 Like