Question: Write a matlab script that finds the root of f ( x ) = e ^ ( - x ) - x using the Secant

Write a matlab script that finds the root of f(x)=e^(-x)-x using the Secant Method, with initial guesses of x0=0 and x1=0.1.
As a reminder, the formula for the Secant method is x_(i+1)=x_i-(f(x_i)(x_(i-1)-x_i))/(f(x_(i-1))-f(x_i))
Implement this formula within a looping structure, iteratively improving your estimate of the solution for the root value until the absolute approximation relative error between the current estimate for a solution and the previous estimate is less than 0.05%.
Upon completion, your script should display the final solution value for the root, the final value of the absolute approximate relative error, and how many iterations it took to arrive at this value. These should be the only things that display in the command window.
Also, output a plot with two lines on the same axes, one for the absolute approximate relative error and the other for the absolute true relative error, with the error percentage on the vertical axis against iteration number on the horizontal axis. To do this, you will need to store the value for each calculated error, as well as each iteration count, in an array(s) every pass through the loop. Include a legend and axis labels. The vertical axis label should specify the indicated errors are in percentage form.
Consider the true solution value for the root to be 0.5671433.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!