MatLab Assignment 3 -- Turn in on October 3



  1. Read through the instructions given in the handout 3 to see how to create and use MatLab M-files.
  2. Write a MatLab program to implement the Bisection Method for solving f(x)=0. With a provided function file fun.m, the program does the following.
  3. Test your program with the equation: x3+x+1=0, [-1,0] and tol=10(-6). The output should be:
         the number of iterations is =
         N =
             20
         cN =
         cN =
             -0.68232822418213
         f(cN) =
         fc =
             -1.007468813263301e-06
    
  4. Use your program to solve the questions with given initial intervals in 5(a), 6, and 7 on Page 62. Use tol=10(-6). Don't forget to create a function file fun.m and edit the file whenever you change a function.
  5. Three MatLab programs for solving f(x)=0 are given below and click on the file name to make a copy.
    (1) falsepos.m (for False-position Method)
    (2) secant.m (for Secant Method)
    (3) newton.m (for Newton's Method)

    The file falsepos.m is a script file and secant.m and newton.m are function files. To run falsepos.m, type falsepos in MatLab.

    Function files are run differently. For secant.m, type [x,flag,ct]=secant(x0,x1,tol,kmax) and type [x,flag,ct]=newton(x0,tol,kmax) for newton.m. Type help filename to see the details about the file. For example, type help newton and the description of this file will be displayed on the screen.

    You need to create two MatLab functions: fun.m and fpfun.m to evaluate the function and the derivative function, respectively, for a given x. You have more than one function to use for your project. You may put all needed functions in the file fun.m and their derivatives in fpfun.m. Put the symbol % at the beginning of each function and delete % only for the function you are currently using.

  6. Suppose we know that each of the following equations
           1/x-tan(x)=0, [pi/100, pi/3]
           2^x+exp(x)+2*cos(x)-6=0, [1,3]
    
    has a unique solution in the given interval [a,b]. Use three given MatLab programs to find an approximation xn of the solution x* for each equation such that either |xn-x*|<10(-6) or |f(xn)|<10(-6) is satisfied. For each algorithm, report the following results for each equation:
    (1) the approximation xn;
    (2) value f(xn); and
    (3) the number of iterations n.


You may use diary to record computation results obtained by MatLab and use Notepad or any word processor to edit the text before turn it in as the project report.