Page 195 - Applied Numerical Methods Using MATLAB
P. 195

184    NONLINEAR EQUATIONS
              2. The bisection method and the false position method appearing in the next
                section will definitely give us the solution, only if the solution exists
                uniquely in some known interval. But the convergence of the fixed-
                point iteration depends on the derivative of g(x) as well as the initial
                value x 0 .
              3. The MATLAB built-in routine fzero(f,x) finds a zero of the function
                given as the first input argument, based on the interpolation and the bisec-
                tion method with the initial solution interval vector x = [ab] given as
                the second input argument. The routine is supposed to work even with an
                initial guess x = x 0 of the (scalar) solution, but it sometimes gives us a
                wrong result as illustrated in the following example. Therefore, it is safe
                to use the routine fzero() with the initial solution interval vector [ab]as
                the second input argument.

           Example 4.2. Bisection Method. Consider the problem of solving the nonlinear
           equation
                                 f 42 (x) = tan(π − x) − x = 0         (E4.2.1)


              Noting that f 42 (x) has the value of infinity at x = π/2 = 1.57 ... ,weset
           the initial solution interval to [1.6, 3] excluding the singular point and use the
           MATLAB routine “bisct()” as follows. The iteration seems to be converging
           to the solution as we expect (see Fig. 4.2b).

            >>f42 = inline(’tan(pi - x)-x’,’x’);
            >>[x,err,xx] = bisct(f42,1.6,3,1e-4,50);
            >>xx
              2.3000  1.9500  2.1250  2.0375  1.9937  2.0156 ... 2.0287
           But, if we start with the initial solution interval [a, b] such that f(a) and f(b)
           have the same sign, we will face the error message.

            >>[x,err,xx] = bisct(f42,1.5,3,1e-4,50);
              ??? Error using  ==> bisct
              We must have f(a)f(b)<0!

              Now, let’s see how the MATLAB built-in routine fzero(f,x) works.

            >> fzero(f42,[1.6 3])
               ans = 2.0287 %good job!
            >> fzero(f42,[1.5 3])
               ??? Error using  ==> fzero
               The function values at interval endpoints must differ in sign.
            >> fzero(f42,1.8) %with an initial guess as 2 nd  input argument
               ans = 1.5708  %wrong result with no warning message
           (cf) Not all the solutions given by computers are good, especially when we are careless.
   190   191   192   193   194   195   196   197   198   199   200