Numerical differentiation can be approached in at least two ways. The first approach uses the Taylor series expansion, while the second is based on the polynomial approximation of a function. We will use a combination of both methods, giving a complete picture of the situation.
Starting from the polynomial approximation:
f(x) = pn(x) + En(x)
Differentiating both sides successively gives:
f′(x) = p′n(x) + E′n(x)
f″(x) = p″n(x) + E″n(x)
f‴(x) = p‴n(x) + E‴n(x)
...
Therefore, to evaluate the derivative of a function known at points ((xi, f(xi)) for i = 0, 1, 2, ..., n), it suffices to differentiate the interpolation polynomial passing through these points. The associated error term is simply the derivative of the interpolation error. This is true for derivatives of any order.
Remark: Although theoretically we can estimate derivatives of any order, in practice, we rarely go beyond the 4th order due to the numerical instability of differentiation.
First-Order Derivatives
The approximation of first-order derivatives corresponds to evaluating the slope of the function f(x). As with interpolation, we can choose polynomials of different degrees, which determines the order and accuracy of the approximation. If a polynomial of degree n is used, the approximation is of order (n+1).
The interpolation error is:
En(x) = f(n+1)(ξ(x)) / (n+1)! * (x−x₀)(x−x₁)…(x−xn)
Differentiating this expression, considering the dependence of ξ on x, gives the derivative of the interpolation error:
E′n(x) = f(n+2)(ξ(x)) ξ′(x) / (n+1)! + f(n+1)(ξ(x)) / (n+1)! * [(x−x₀)(x−x₁)…(x−xn)]′
Evaluating at x = xi simplifies the expression because the first term disappears, leaving:
E′n(xi) = f(n+1)(ξi) / (n+1)! * Πj=0, j≠in (xi−xj)
If the points are equally spaced, xi+1 − xi = h, then:
E′n(xi) = f(n+1)(ξi) * hⁿ / (n+1)! * Πj=0, j≠in (i−j)
In particular, for i=0:
E′n(x₀) = (−1)ⁿ * hⁿ * f(n+1)(ξ₀) / (n+1)!
Remark: Equation above shows that using an interpolation polynomial of degree n (order n+1), the derivative of this polynomial evaluated at xi is an approximation of order f′(xi).