Page 99 -
P. 99

deryn=dyn./dxn;
                                plot(n,deryn)

                             The limit of the deryn’s sequence is clearly equal to 1, the value of this func-
                             tion derivative at 0.
                             NOTE The choice of N should always be such that dxn is larger than the
                                                                    53
                             machine precision; that is, N < 53, since (1/2) ≈ 10 .
                                                                         –16

                             In-Class Exercises
                             Find numerically, to one part per 10,000 accuracy, the derivatives of the fol-
                             lowing functions at the indicated points:

                                           3
                                      4
                             Pb. 4.6  x (cos ( x) sin(−  2 x)) at  x   → π
                                      exp(x +  ) 3
                                           2
                             Pb. 4.7              at  x →  0
                                     (2 +  cos ( ))x
                                            2
                                     (1+  sin ( ))x
                                            2
                             Pb. 4.8              at  x  → π / 2
                                     (2 −  cos ( ))x
                                            3
                                         x − 12
                                            / 
                             Pb. 4.9  ln   x + 1    at  x → 1
                                         −1
                             Pb. 4.10  tan (x 2  +  ) 3  at    → 0x

                             Example 4.3
                                                            2
                             Plot the derivative of the function x  sin(x) over the interval 0 ≤ x ≤ 2π.
                             Solution: Edit and execute the following script M-file:

                                dx=10^(-4);
                                x=0:dx:2*pi+dx;
                                df=diff(sin(x).*x.^2)/dx;
                                plot(0:dx:2+pi,df)

                             where diff is a MATLAB command, which when acting on an array X, gives
                             the new array [X(2) – X(1)X(3) – X(2) … X(n) – X(n – 1)], whose length is one
                             unit shorter than the array X.
                              The accuracy of the above algorithm depends on the choice of dx. Ideally,
                             the smaller it is, the more accurate the result. However, using any computer,
                             we should always choose a dx that is larger than the machine precision, while



                             © 2001 by CRC Press LLC
   94   95   96   97   98   99   100   101   102   103   104