Page 211 - Applied Numerical Methods Using MATLAB
P. 211

200    NONLINEAR EQUATIONS
                   5



                                           y = x
                   0

                                                  y = tan (p − x)

                  −5
                         −1       0        1        2       3        4
                    Figure P4.2 The graphical solutions of tan(π − x) − x = 0ortan(π − x) = x.


                   (cf) This helps us understand why fzero(fp42,1.8) leads to the wrong solu-
                       tion even without any warning message as mentioned in Example 4.2.
                (c) In order to find the solution around x = 2.0 by using the fixed-point
                   iteration with the initial point x 0 = 2.0, Vania defined the iterative func-
                   tion as


                    >>gp421 = inline(’tan(pi - x)’,’x’); % x = g 1 (x) = tan (π − x)

                   and typed the following statement into the MATLAB command window.

                    >>x = fixpt(gp421,2,TolX,MaxIter)


                   Could she reach the solution near 2? Will it be better if you start the
                   routine with any different initial point? What is wrong?
                (d) Itha, seeing what Vania did, decided to try with another iterative formula

                              −1                            −1
                           tan  x = π,    x = g 2 (x) = π − tan  x      (P4.2.2)

                   So she defined the iterative function as


                                                                          −1
                     >>gp422 = inline(’pi-atan(x)’, ’x’); % x = g(x) = π − tan (x)
                   and typed the following statement into the MATLAB command window:


                    >>x = fixpt(gp422,2,TolX,MaxIter)

                   What could she get? Is it the right solution? Does this command work
                   with different initial value, like 0 or 6, which are far from the solution
                   we want to find? Describe the difference between Vania’s approach and
                   Itha’s.
   206   207   208   209   210   211   212   213   214   215   216