This note compares the result of computing the numerical derivative to at using Taylor approximation using single ﬂoating point and double ﬂoating point. This was done using Matlab. With Matlab, we can do single ﬂoating point computation using the single command. The default in Matlab is to do all the computations in double precision.
The approximation used is with starting at and halving it at each iteration.
The exact answer to evaluated at is The results below show that using single precision, the numerical derivative keeps getting closer the exact answer up to iteration 12. The best answer is accuracy to 4 decimal places. After iteration 12, subtractive cancellation (loss of signiﬁcance, L.O.S) become more dominant, and the result starts to become less accurate.
Using double precision, we see that we can go up to iteration 27 before loss of signiﬁcance kicks in. The best numerical result at this point is accurate to 8 decimal points. Hence the accuracy is twice that of single precision.
The following diagram displays the results table for single precision, with a red box around the line where the numerical results starts to be aﬀected by L.O.S. with the Matlab code used.
The following diagram displays the results table for double precision, with a red box around the line where the numerical results starts to be aﬀected by L.O.S. The Matlab code is the same as before, expect we simplify remove the command single wherever it was used.