- #1
aleee
- 17
- 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
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