Matlab steffensens method

  • MATLAB
  • Thread starter aleee
  • Start date
  • #1
17
0
i gotta 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 dont 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
 

Answers and Replies

  • #2
17
0
figured it out, comment if curious.
 

Related Threads on Matlab steffensens method

  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
1
Views
22K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
1
Views
6K
  • Last Post
Replies
4
Views
23K
Replies
0
Views
2K
Replies
0
Views
8K
  • Last Post
Replies
2
Views
41K
  • Last Post
Replies
7
Views
8K
Top