If we could let h=0, then this equation would return the exact derivative. However, h=0 is obviously not
allowed. Further, we can't just make h arbitrarily small, because the loss of precision degrades the
answer. This can be seen by using nDeriv() with various values of h. The table below shows the results
returned by nDeriv() for f(x) = tan(x), with various values of h, and with x = 1
1.712E+001.7127 5941 0411E-14
-1.713E-133.5967 9476 1861E-13
-1.000E-133.4272 3158 0231E-11
-1.000E-133.4255 1882 0811E-10
-1.000E-133.4255 1882 0811E-09
-1.000E-133.4255 1882 0811E-08
-1.000E-133.4255 1882 0811E-07
1.712E-083.4255 1880 371E-06
-2.886E-093.4255 1882 371E-05
-9.456E-083.4255 1891 5381E-04
-9.451E-063.4255 2827 1331E-03
-9.453E-043.4264 6416 0081E-02
-9.749E-023.5230 0719 8491E-01
errorf'(x)h
This seems to be very good performance - too good, in fact. Suppose that instead of including the
tan(x) function in nDeriv(), we call the function indirectly, like this:
nDeriv(ftan(xx),xx,h)|xx=1
where ftan() is just a user function defined to return tan(x). This results in the following:
3.43E+0001E-14
-7.45E-023.51E-13
2.55E-023.41E-12
5.19E-043.4251E-11
-1.88E-053.42551E-10
-1.88E-053.42551E-09
-1.18E-063.425521E-08
3.21E-073.42551851E-07
2.08E-083.42551881E-06
8.15E-083.425518821E-05
-9.42E-083.4255189151E-04
-9.45E-063.425528271351E-03
-9.45E-043.4264641600851E-02
-9.75E-023.52300719849151E-01
errorf'(x)h
This is more typical of the performance we would expect from the central difference formula. As h
decreases, the number of digits in the results decreases, because of the increasingly limited resolution
of f(x+h) - f(x-h). The accuracy gets better until h = 1E-6, then starts getting worse. At the best error,
we only have 8 significant digits in the result.
This example seems to imply that the 89/92+ does not directly calculate the central difference formula
to estimate the derivative of tan(x). Instead, the 89/92+ uses trigonometric identities to convert
6 - 36