How to Implement Steffensen's Method in Matlab for Solving Equations

  • Context: MATLAB 
  • Thread starter Thread starter aleee
  • Start date Start date
  • Tags Tags
    Matlab Method
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 4K views
aleee
Messages
17
Reaction score
0
i got to to write a program for steffensens method on matlab.
my equation is x=cosx and my initial value is x0=2 and got to do up to the 14 iterations.
error = x_n - a

a= 0.7390851332151607
i don't get an answer close to it.
i get something around 10.xxxx
here is my code.

function root = steff(x0,max_iterations)

format long e;
it_count = 0;
exact = 0.7390851332151607;
f = x0 - cos(x0);
g = (cos(cos(x0)) - x0 - 2*f) / f;

while it_count <= max_iterations;

x1 = x0 - f^2/(cos(cos(x0)) - x0 - 2*f);

error = x1 - exact;
iteration = [it_count x0 error]
x0 = x1;
it_count = it_count + 1;

end
format long e
root = x1
format long e
error
format long
it_count
 
on Phys.org
figured it out, comment if curious.