Homework Set No. 5, Numerical Computation: 1. Bisection Method
Homework Set No. 5, Numerical Computation: 1. Bisection Method
5, Numerical Computation
1. Bisection method
We consider the bisection method to find a root for f (x) = 0. If f (0) < 0 and f (1) > 0,
then there is a root on the interval [0, 1], and we take [0, 1] as the initial interval. How
many steps of the bisection method are needed to obtain an approximation to the root,
if the absolute error is ≤ 10−8 ? (Note that this number does not depend on the actual
function!)
Given a function f (x) = e−x − cos(x). We want to find a root r such that f (r) = 0.
(a). First, show that there is a root in the interval [1.1, 1.6].
(b). Now we try to locate this root by fixed point iteration. First, we observe that
f (x) = 0 is equivalent to
Set up a corresponding fixed point iteration scheme. Then, choose a starting point
x0 = 1.6, and do 4 iterations to compute the values x1 , x2 , x3 , x4 . What do you
observe? Does the method converge? Why?
Based on this new function, set up the corresponding fixed point iteration. Then,
choose the starting point x0 = 1.6, and do 4 iterations to compute the values
x1 , x2 , x3 , x4 . What is your result? How different is it from part (b)? Does the
method converge? Why?
1
4. Newton’s method
√
As you have seen in the lecture, the computation of R can be done by finding the root
of f (x) = x2 − R with Newton’s method.
c). Now we test the iterations for R = 10. Choose x0 = 3, and compute x1 , x2 x3 and
x4 . Use 8 digit in your computation. Comment on your result.
f (x) = (x − 1)m .
(b). Now use the initial guess x0 = 1.1 (note that this is very close to the root r = 1).
Complete 4 iterations to compute the values x1 , x2 , x3 , x4 .
(c). How does the method work for this problem? Can you explain why?
(d). If we have m = 20, or for m with large value, could you predict the behavior of
Newton’s iteration? Explain in detail.
a). Calculate an approximate value for 43/4 using the secant method with x0 = 3 and
x1 = 2. Make 3 steps, and compute the values x2 , x3 , x4 . Comment on your result.
b). Use secant method to find the root for f (x) = x3 − 2x + 1 with x0 = 4 and x1 = 2.
Compute the values x2 , x3 and x4 . Does the method converge? (You can easily
check that x = 1 is a root.)
2
c). Consider an iteration scheme
Preparation: Use “help sprintf” and “help disp” in Matlab to understand how
to use “sprintf” and “disp” to display the data. Here is an example:
The problem: Write a Matlab function for Newton’s method. Your file mynewton.m
should start with:
function x=mynewton(f,df,x0,tol,nmax)
where f,df are the function f and its derivative f ′ , x0 is the initial guess, tol is the error
tolerance, nmax is the maximum number of iterations, and x is the result. Use sprintf
and “disp” to display your result in each iteration so you can check the convergence
along the way.
√
First, test your function with the example we had in class, computing 2. Then, use
your Matlab function to find a root of f (x) = e−x − cos(x) on the interval [1.1, 1.6]. Use
tol=1e-12 and nmax=10. You should choose an initial guess x0 on the interval [1.1, 1.6].
What is your answer?
What to hand in: Print out your files mynewton.m,
√ files for functions f (x) and f ′ (x),
script file, test result for the example of 2 and for the root of f (x) = e−x − cos(x).
Write a Matlab function to locate a root by secant method. Your function should be
put in the file mysecant.m, and should be called as
x=mysecant(f,x0,x1,tol,nmax)
Here f is the function f , x0,x1 are the initial guesses, tol is the error tolerance, nmax
is the maximum number of iterations, and x is the output of your function.
3
√
Test your function to find the value 2, as the root for f (x) = x2 − 2, to see if it works.
Use sprintf and “disp” to display your result in each iteration, so you can check the
convergence.
Then, use it to find a root for the function f (x) = e−x − cos(x) in the interval [1.1, 1.6].
Use tol=1e-12 and nmax=10. How does the result compare to those with Newton’s
method? Comment in detail.
What to hand in: print out your file mysecant.m, test result for f (x) = x2 − 2, and
the result for f (x) = e−x − cos(x).