Write a MATLAB user-defined function that solves for a root of a nonlinear equation f(x) = 0
Question:
Write a MATLAB user-defined function that solves for a root of a nonlinear equation f(x) = 0 using the bisection method. Name the function Xs = Bi sec t i onRoot(Fun, a, b). The output argument Xs is the solution. The input argument Fun is a name for the function that calculates f(x) for a given x (it is a dummy name for the function that is imported into BisectionRoot); a and b are two points that bracket the root. The iterations should stop when the tolerance in f(x) (Eq. (3.5)) is smaller than 0.000001. The program should check if points a and b are on opposite sides of the solution. If not, the program should stop and display an error message. Use BisectionRoot to solve Problem 3.2.
Eq. 3.5 is given below
Determine the root of f(x) = x - 2e -x by:
(a) Using the bisection method. Start with a=0 and b=1, and carry out first three iteration.
(b) Using the secant method. Start with the two points, x 1 = 0 and x 2 = 1, and carry out the first three iteration.
(c) Using Newton's method. Start x 1 =1 and carry out the first three iteration.