Question: The Secant Method in Matlab Write a Matlab function to locate a root by the secant method. Your function should be put in the file

The Secant Method in Matlab Write a Matlab function to locate a root by the 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. Test your function to find the value Squareroot 2, as the root for f(x) = x^2 - 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. Your two initial guesses should be on the interval [1.1, 1.6]. How does the result compare to those with Newton's method? Comment in detail. What to hand in: Your file mysecant.m, test result for f(x) = x^2 - 2, and the result for f(x) = e^-x - cos(x)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
