Example
Consider the centered three-point formula for the first derivative:
,
then we can calculate successive approximations, halving the step size each time, and monitor the accuracy of the value obtained by using Richardson Extrapolation:
> restart:f:=x->ln(cos(x));
> df:=D(f):ddf:=D(df):dddf:=D(ddf):
> h:=0.1:df1[1]:=1/(2*h)*(f(0.4+h)-f(0.4-h)):acterr:=abs(df1[1]-df(0.4)): print(h,df1[1],acterr);
> for i from 2 to 5 do h:=0.1/(2^(i-1)): df1[i]:=1/(2*h)*(f(0.4+h)-f(0.4-h)): acterr:=abs(df1[i]-df(0.4)): Q:=(4*df1[i]-df1[i-1])/3: newerr:=abs(Q-df(0.4)): print(h,df1[i],acterr,Q,newerr);od:
We can actually monitor the behaviour of the error:
> for i from 2 to 5 do h:=0.1/(2^(i-1)): df1[i]:=1/(2*h)*(f(0.4+h)-f(0.4-h)): acterr:=abs(df1[i]-df(0.4)): Q:=(4*df1[i]-df1[i-1])/3: newerr:=abs(Q-df(0.4)): print(h,acterr/h^2,newerr/h^4);od: