Page 196 - Applied Numerical Methods Using MATLAB
P. 196

FALSE POSITION OR REGULA FALSI METHOD  185
                                                          x 4
             k   a k   x k   b k    f(x )                2.0375
                                      k
                                              5
             0  1.6         3.0   32.6, −2.86           x   x 3
             1  1.6  2.3    3.0    −1.1808               2  2.125  x
             2  1.6  1.95   2.3     0.5595             1.95      1
                                                                2.3
             3  1.95  2.125  2.3   −0.5092    0
             4  1.95  2.0375  2.125  −0.5027
             .   .     .     .        .
             .   .     .     .        .
             .   .     .     .        .
                                               1.6  1.8  2   2.2  2.4  2.6  2.8
               (a) Process of the bisection method  (b) The graph of f(x) = tan(p − x) − x
                            Figure 4.2 Bisection method for Example 4.2.




            4.3  FALSE POSITION OR REGULA FALSI METHOD

            Similarly to the bisection method, the false position or regula falsi method starts
            with the initial solution interval [a, b] that is believed to contain the solution of
            f(x) = 0. Approximating the curve of f(x) on [a, b] by a straight line connecting
            the two points (a, f (a)) and (b, f (b)), it guesses that the solution may be the
            point at which the straight line crosses the x axis:

                        f(a)                    f(b)             af (b) − bf (a)
             x = a −            (b − a) = b −           (b − a) =
                     f(a) − f(b)             f(b) − f(a)          f(a) − f(b)
                                                                         (4.3.1)

             function [x,err,xx] = falsp(f,a,b,TolX,MaxIter)
             %bisct.m to solve f(x)=0 by using the false position method.
             %input : f  = ftn to be given as a string ’f’ if defined in an M-file
             %       a/b = initial left/right point of the solution interval
             %      TolX = upperbound of error(max(|x(k)-a|,|b-x(k)|))
             %   MaxIter = maximum # of iterations
             %output: x  = point which the algorithm has reached
             %       err = max(x(last)-a|,|b-x(last)|)
             %       xx  = history of x
             TolFun = eps; fa = feval(f,a); fb=feval(f,b);
             if fa*fb > 0, error(’We must have f(a)f(b)<0!’); end
             fork=1: MaxIter
               xx(k) = (a*fb-b*fa)/(fb-fa); %Eq.(4.3.1)
               fx = feval(f,xx(k));
               err = max(abs(xx(k) - a),abs(b - xx(k)));
               if abs(fx) < TolFun | err<TolX, break;
                elseif fx*fa > 0, a = xx(k); fa = fx;
                else  b = xx(k); fb = fx;
               end
             end
             x = xx(k);
             if k == MaxIter, fprintf(’The best in %d iterations\n’,MaxIter), end
   191   192   193   194   195   196   197   198   199   200   201