 Higher order derivatives of unequally spaced data - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: Not HP Calculators (/forum-7.html) +--- Forum: Not remotely HP Calculators (/forum-9.html) +--- Thread: Higher order derivatives of unequally spaced data (/thread-17217.html) Higher order derivatives of unequally spaced data - Namir - 07-06-2021 08:48 PM Hi All, I found on the Internet several documents and power points that describe how to estimate the first and second derivatives of unequally spaced points based on quadratic Lagrangian polynomials. I posted on my web site (click here to download) a short paper that presents first, second, third, and fourth derivatives based on cubic and quartic Lagrange polynomials. I used some free online tools to help me formulate the equations for these derivative estimates. The paper includes the pseudo-code for these methods along with source code in Excel VBA, Matlab, and Python. These derivatives are helpful in estimating the rate of changes in physical of chemical process where the physical/chemical property is measured at irregular intervals. Namir RE: Higher order derivatives of unequally spaced data - Albert Chan - 07-07-2021 05:45 PM For derivatives, we may remove 1 term of Lagrange polynomial. (f(x))' = (f(x) - c)', for constant c Example, with 3 points: $$f(x) ≈ f(x_1)\left({(x-x_2)(x-x_3) \over (x_1-x_2)(x_1-x_3)}\right) + f(x_2)\left({(x-x_1)(x-x_3) \over (x_2-x_1)(x_2-x_3)}\right) + f(x_3)\left({(x-x_1)(x-x_2) \over (x_3-x_1)(x_3-x_2)}\right)$$ Let $$c = f(x_2)$$, we eliminated middle term: $$f'(x) ≈ \Big(f(x_1) - f(x_2)\Big) \left({(x-x_2)+(x-x_3) \over (x_1-x_2)(x_1-x_3)}\right) + \Big(f(x_3) - f(x_2)\Big) \left({(x-x_1)+(x-x_2) \over (x_3-x_1)(x_3-x_2)}\right)$$ Simplify with Divided Differences Notation: \begin{align} f'(x) &≈ {f[x_1,x_2] \over x_3-x_1} (x_2+x_3-2x) + {f[x_2,x_3] \over x_3-x_1} (2x-x_1-x_2) \\ &= {f[x_1,x_2] \over x_3-x_1} (x_2+x_3-2x) + \left(f[x_1,x_2,x_3] + {f[x_1,x_2] \over x_3-x_1}\right) (2x-x_1-x_2) \\ &= f[x_1,x_2] + f[x_1,x_2,x_3] \, (2x-x_1-x_2) \end{align} We can confirm above, with 3-points Divided-difference formula $$f(x) ≈ f(x_1) + (x-x_1) \Big(f[x_1,x_2] + (x-x_2)\,f[x_1,x_2,x_3] \Big)$$ Differentiate with respect to x, we get back the same f'(x) RE: Higher order derivatives of unequally spaced data - Namir - 07-10-2021 11:05 PM Thanks Albert! I may updated my paper to include a version of algorithms and source codes that are based on Newton divided-difference polynomials. Namir RE: Higher order derivatives of unequally spaced data - Namir - 07-17-2021 12:45 PM Hi All, I have updated my original paper to include higher order derivatives of unequally spaced data using Newton's divided-difference interpolation polynomials. The update also includes source code functions in Excel VBA, Matlab, and Python. To access the updated paper click here. Enjoy! Namir