Page 255 -
P. 255

This is implemented in the code as follows:

                                   W=ones(M,N);
                                   for i=1:M
                                     for j=2:N
                                     W(i,j)=x(i)*W(i,j-1)/(j-1);
                                     end
                                   end

                                4. The value of the truncated series at a specific point is the sum of
                                   the row elements corresponding to its index; however since MAT-
                                   LAB command sum acting on a matrix adds the column elements,
                                   we take the sum of the adjoint (the matrix obtained, for real ele-
                                   ments, by changing the rows to columns and vice versa) of W to
                                   obtain our result. Consequently, add to the code:


                                   serexp=sum(W');

                                5. Finally, compare the values of the truncated series with that of the
                                   exponential function

                                   y=exp(x);
                                   plot(x,serexp,x,y,'--")

                              In examining the plot resulting from executing the above instructions, we
                             observe that the truncated series give a very good approximation to the expo-
                             nential over the whole interval.
                              If you would also like to check the error of the approximation as a function
                             of x, enter:


                                dy=abs(y-serexp);
                                semilogy(x,dy)

                             Examining the output graph, you will find, as expected, that the error
                             increases with an increase in the value of x. However, the approximation of
                             the exponential by the partial sum of the first ten elements of the truncated
                             Taylor series is accurate over the whole domain considered, to an accuracy of
                             better than one part per million.

                             Question: Could you have estimated the maximum error in the above com-
                             puted value of dy by evaluating the first neglected term in the Taylor’s series
                             at x = 1?


                             © 2001 by CRC Press LLC
   250   251   252   253   254   255   256   257   258   259   260