Page 210 - Applied Numerical Methods Using MATLAB
P. 210

PROBLEMS   199
             4.2 Bisection Method and Fixed-Point Iteration
                Consider the nonlinear equation treated in Example 4.2.

                                    f(x) = tan(π − x) − x = 0           (P4.2.1)

                Two graphical solutions of this equation are depicted in Fig. P4.2, which
                can be obtained by typing the following statements into the MATLAB
                command window:

                 >>ezplot(’tan(pi-x)’,-pi/2,3*pi/2)
                 >>hold on, ezplot(’x+0’,-pi/2,3*pi/2)

                (a) In order to use the bisection method for finding the solution between
                    1.5 and 3, Charley typed the statements shown below. Could he get the
                    right solution? If not, explain him why he failed and suggest him how
                    to make it.

                     >>fp42 = inline(’tan(pi-x)-x’,’x’);
                     >>TolX = 1e-4; MaxIter = 50;
                     >>x = bisct(fp42,1.5,3,TolX,MaxIter)

                (b) In order to find some interval to which the bisection method is applica-
                    ble, Jessica used the MATLAB command “find()” as shown below.
                     >>x = [0: 0.5: pi]; y = tan(pi-x) - x;
                     >>k = find(y(1:end-1).*y(2:end) < 0);
                     >>[x(k) x(k + 1); y(k) y(k + 1)]
                       ans =  1.5000    2.0000    2.0000   2.5000
                            -15.6014    0.1850    0.1850  -1.7530

                    This shows that the sign of f(x) changes between x = 1.5 and 2.0
                    and also between x = 2.0 and 2.5. Noting this, Jessica thought that she
                    might use the bisection method to find a solution between 1.5 and 2.0
                    by typing the following command.

                     >>x=bisct(fp42,1.5,2,TolX,MaxIter)
                    Check the validity of the solution—that is, check if f(x) = 0 or not—by
                    typing

                     >>fp42(x)
                    If her solution is not good, explain the reason. If you are not sure about
                    it, you can try plotting the graph in Fig. P4.2 by typing the following
                    statements into the MATLAB command window.

                     >>x = [-pi/2+0.05:0.05:3*pi/2 - 0.05];
                     >>plot(x,tan(pi - x),x,x)
   205   206   207   208   209   210   211   212   213   214   215