Fixed Point iteration using matlab, whats wrong with my code?

Click For Summary
SUMMARY

The forum discussion focuses on implementing Fixed Point Iteration in MATLAB to find the root of an equation. The user is struggling with the correct implementation of the while loop and the function g(x). The provided MATLAB code contains a syntax error in the conditional statement for convergence, specifically in the use of parentheses. The correct implementation should ensure that the absolute error condition is properly closed and that the convergence message is displayed after the loop concludes.

PREREQUISITES
  • Understanding of Fixed Point Iteration method
  • Proficiency in MATLAB programming
  • Familiarity with function definitions in MATLAB
  • Knowledge of error tolerance in numerical methods
NEXT STEPS
  • Review MATLAB syntax for conditional statements and loops
  • Learn about error handling in MATLAB functions
  • Explore numerical methods for root-finding, specifically Newton's method
  • Investigate MATLAB's built-in functions for optimization and root-finding
USEFUL FOR

Students and professionals in computational mathematics, MATLAB programmers, and anyone interested in numerical methods for solving equations.

megr_ftw
Messages
68
Reaction score
0
Fixed Point iteration using matlab, what's wrong with my code??

Homework Statement


We are suppose to use MatLab to make a program using the fixed point iteration to find the root of an equation.
I just can't figure out what I'm doing wrong here...

I'm pretty sure a while loop is the appropriate measure to use, but how should I go about plugging in g(x) which is the modified form of the original equation..

Homework Equations





The Attempt at a Solution



%finds the approximate root using fixed point iteration
%input: inline function g(x)
%guess point x0
%max error (err_max)
%number of iterations (n)
%output: x is the approx. root
%k is the number of iterations carried out

function root= fixed_point(g,x0,n,err_max)
i=1;
x(1)=g(x0);
while i<=n
x(i+1)=g(x(i));
if abs((x(i+1)-x(i))/(x(i+1)) < err_max
disp('Converges after k iterations')
k=i;
disp('The root to the equation is')
x(i+1)
return
end
i=i+1;
end
 
Physics news on Phys.org


What kind of error are you getting?
 


Could you comment your code? I can't quite figure out how this is supposed to perform fixed point iteration.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
1K
  • · Replies 16 ·
Replies
16
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
967
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K