Page 146 -
P. 146

In-Class Exercises

                             In each of the following problems, find the zeros of the following functions
                             over the interval [0, 5].
                                           2
                             Pb. 5.6 f(x) = x  + 1. (Alert: Applying fsolve blindly could lead you into
                             trouble!)
                                            2
                             Pb. 5.7 f(x) = sin (x) – 1/2. Compare your answer with the analytical result.
                                              2
                             Pb. 5.8 f(x) = 2 sin (x) – x 2
                             Pb. 5.9 f(x) = x – tan(x)



                             Zeros of a Function in Two Variables
                             As previously noted, the power of the MATLAB fsolve function really
                             shines in evaluating the roots of multivariable functions.

                             Example 5.3
                             Find the intersection in the x-y plane of the parabaloid and the plane given in
                             Pb. 5.1.

                             Solution: We follow these steps:

                                1. Use the  contour command to estimate the coordinates of the
                                   points of intersection of the surfaces in the x-y plane.
                                2. Construct the function M-file for two functions (z , z ) having two
                                                                              1  2
                                   inputs (x, y):

                                   function farray=funname(array)
                                   x=array(1);
                                   y=array(2);
                                   farray(1)=7-sqrt(25+x.^2+y.^2);
                                   farray(2)=4-2*x-4*y;

                                3. Use the approximate value found in step 1 as the value for the
                                   guess array; for example:

                                   xyguess=[4 -1];

                                4. Finally, use the fsolve command to accurately find the root. The
                                   syntax is:



                             © 2001 by CRC Press LLC
   141   142   143   144   145   146   147   148   149   150   151