Derivation
Often, one can not choose the step size
arbitrarily small. The function value may only be known as a table so that the smallest step size is determined by the tabulated values. Or, the values are calculated values, part of a bigger numerical scheme. Therefore, formulae that yield a more accurate estimate with larger values of
are worthwhile pursuing.
Here, we will construct a number of three point formulae: formulae that use three data points instead of two. Take the result of Theorem 10 with the quadratic Lagrange Polynomial:
.
Again, we can take the derivative of both sides to obtain a formula for
. First, consider the Lagrange Polynomial:
> restart;
> P2:=xx->((xx-x[1])*(xx-x[2])/((x[0]-x[1])*(x[0]-x[2])))*f(x[0])+((xx-x[0])*(xx-x[2])/((x[1]-x[0])*(x[1]-x[2])))*f(x[1])+((xx-x[0])*(xx-x[1])/((x[2]-x[0])*(x[2]-x[1])))*f(x[2]);
> dP2:=diff(P2(xx),xx);
or, with equidistant points such that
> x[1]:=x[0]+h;x[2]:=x[0]+2*h;
> dP2;
The error term can also be dealt with:
> err:=(D@@3)(f)(xi(xx))/(3!)*(xx-x[0])*(xx-x[1])*(xx-x[2]);
> derr:=diff(err,xx);
This error term is difficult to manipulate, but can be simplified by evaluating the expression at any of the data points
> dfx:=dP2+derr;
> dfx0:=simplify(subs(xx=x[0],dfx));
> dfx1:=simplify(subs(xx=x[1],dfx));
> dfx2:=simplify(subs(xx=x[2],dfx));
The first and third formulae can be written in the same format if we allow
:
.
This represents the formula to be used when the data points are all on one side of the point at which you want to evaluate the derivative.
When a data point is located at either side of the point at which the derivative needs to be evaluated, the formula becomes
.
Notice that the error here is about half the error of the previous formula. Therefore, this centered difference is usually preferred.