UCB Math 128A, Spring 2014: Programming Assignment 1Due February 25In this assignment, we will address two issues with the Bisection method and Newton’s method:• Finding an interval [a, b] for the Bisection method, with f(a) and f (b) having different signs.• Combining the excellent convergence properties of Newton’s method with the guaranteedroot-finding of the Bisection method.1. Implement a MATLAB function findbracket of the formfunction [a,b]=findbracket(f,x0)which finds an interval [a, b] around x0such that f(a) and f(b) have different signs. Use thefollowing strategy:1. Start with a = b = x0, and dx = 0.0012. Subtract dx from a, and terminate if f(a)f(b) < 03. Add dx to b, and terminate if f(a)f(b) < 04. Multiply dx by 2 and repeat from step 2.2. Implement a MATLAB function newtonbisection of the formfunction p=newtonbisection(f,df,a,b,tol)combining Newton’s method and the Bisection method according to the following strategy:1. Start with p = a2. Attempt a Newton step p = p − f (p)/f0(p)3. If p is outside of [a, b], set p = (a + b)/24. If f(p)f(b) < 0, set a = p, otherwise set b = p5. Terminate if |f(p)| < tol6. Repeat from step 2.Use the functions newton and bisection on the course web page as a starting point, thisfunction will be like a combination of the two.3. Run your function newtonbisection using f(x) = sin x − e−xon the interval [1.9, 30]:f=@(x) sin(x)-exp(-x);df=@(x) cos(x)+exp(-x);x=newtonbisection(f,df,1.9,30,1e-8);Present the result in a table showing for each iteration the method used (Newton or Bisect),a, b, p, and f(p).Turn page −→4. Use your combined findbracket and newtonbisection to solve for the roots of f (x) =sin x − e−xwith x0= −3, −2, . . . 10:f=@(x) sin(x)-exp(-x);df=@(x) cos(x)+exp(-x);for x0=-3:10[a,b]=findbracket(f,x0);x=newtonbisection(f,df,a,b,1e-8);[x0,a,b,x]endPresent your results in a table showing x0, a, b, and x.Reporting requirements:The GSIs will not run any submitted MATLAB codes. Prepare a report showing the requestedinformation, which is essentially just your MATLAB functions and the computed tables. Givebrief comments if things do not work as
View Full Document