home
PDF

Taylor series approximation. Single/double floating point comparison

Nasser M. Abbasi

May 3,2007 page compiled on June 29, 2015 at 4:38am

This note compares the result of computing the numerical derivative to arctan (x)  at     √ --
x =   2  using Taylor approximation using single floating point and double floating point. This was done using Matlab. With Matlab, we can do single floating point computation using the single command. The default in Matlab is to do all the computations in double precision.

The approximation used is f ′(x) = 1h (f (x + h) − f (x ))  with h  starting at 1  and halving it at each iteration.

The exact answer to darctan(x)
   dx  evaluated at x =  √2-  is 1∕3.  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 significance, 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 significance 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 affected by L.O.S. with the Matlab code used.

PIC

The following diagram displays the results table for double precision, with a red box around the line where the numerical results starts to be affected by L.O.S. The Matlab code is the same as before, expect we simplify remove the command single wherever it was used.

PIC