How do I display my secant method iteration values in a table?
Show older comments
Here is my code for the secant method approximation of the function.
func = @(x) 2*exp(-2*x) + 4*sin(x) - 2*cos(2*x);
x1 = 2.5;
x2 = 2.4;
tol = 1e-9;
f1 = func(x1);
dx = inf;
iter = 0;
while abs(dx) > tol
iter = iter + 1;
f2 = func(x2);
dx = (x2 - x1)*f2/(f2 - f1);
x1 = x2;
f1 = f2;
x2 = x2 - dx;
end
x2
iter
It says that it takes 5 iterations to get to the root. I would like to be able to display each of these iterations with what value they approximate for the root.
Could someone please help me with the code that would be required to do that? Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!