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
Click For Summary
SUMMARY

The discussion focuses on implementing Steffensen's Method in MATLAB to solve the equation x = cos(x) with an initial value of x0 = 2 and a maximum of 14 iterations. The user encountered issues obtaining a root close to the expected value of 0.7390851332151607, instead receiving results around 10.xxxx. The provided MATLAB code includes a function that iteratively calculates the root but requires adjustments to achieve the desired accuracy.

PREREQUISITES
  • Understanding of Steffensen's Method for root-finding
  • Familiarity with MATLAB programming and syntax
  • Knowledge of numerical methods for solving equations
  • Basic understanding of the cosine function and its properties
NEXT STEPS
  • Review MATLAB's built-in functions for root-finding, such as fzero
  • Learn about error analysis in numerical methods
  • Explore convergence criteria for iterative methods
  • Investigate alternative methods for solving nonlinear equations, such as Newton's method
USEFUL FOR

Mathematics students, MATLAB programmers, and anyone interested in numerical methods for solving equations will benefit from this discussion.

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
 
Physics news on Phys.org
figured it out, comment if curious.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
3
Views
4K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
2
Views
42K
  • · Replies 3 ·
Replies
3
Views
19K
  • · Replies 1 ·
Replies
1
Views
9K
Replies
7
Views
9K
  • · Replies 9 ·
Replies
9
Views
2K