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

In summary, the conversation is about writing a program for Steffensen's method on MATLAB. The equation is x=cosx and the initial value is x0=2. The program needs to be able to perform up to 14 iterations and calculate the error using the formula error = x_n - a. The desired output is a value close to a=0.7390851332151607, but the current code is giving a result around 10.xxxx. The code is then provided and it is mentioned that the issue has been resolved.
  • #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
 
Physics news on Phys.org
  • #2
figured it out, comment if curious.
 

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

1. What is Matlab Steffensen's Method?

Matlab Steffensen's Method is a numerical method used for finding the roots of a given function. It is an iterative method that uses successive approximations to converge on the root of a function.

2. How does Matlab Steffensen's Method work?

This method works by starting with an initial guess for the root and then using a formula to generate a new approximation. This process is repeated until the approximation is close enough to the actual root, within a specified tolerance.

3. What are the advantages of using Matlab Steffensen's Method?

One advantage of this method is that it can converge much faster than other iterative methods, such as the bisection method or the Newton-Raphson method. It also does not require the calculation of derivatives, making it useful for functions that are difficult to differentiate.

4. What are the limitations of Matlab Steffensen's Method?

This method may not work if the initial guess is too far from the actual root or if the function has multiple roots. It also requires the function to be continuous and differentiable in the given interval.

5. How do I implement Matlab Steffensen's Method in my code?

In Matlab, this method can be implemented using a for loop or a while loop to iterate through the formula until the desired tolerance is reached. The function and initial guess must also be defined beforehand. There are also built-in functions in Matlab, such as "fzero", that use Steffensen's Method for root finding.

Similar threads

Replies
3
Views
4K
  • Programming and Computer Science
Replies
7
Views
3K
  • Precalculus Mathematics Homework Help
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
42K
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
Back
Top