• Support PF! Buy your school textbooks, materials and every day products Here!

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

  • Thread starter megr_ftw
  • Start date
  • #1
71
0
Fixed Point iteration using matlab, whats 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
 

Answers and Replies

  • #2
CEL
656
0


What kind of error are you getting?
 
  • #3
3
0


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

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

Replies
1
Views
19K
Replies
9
Views
434
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
3
Views
1K
Replies
17
Views
11K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
3
Views
2K
Replies
51
Views
23K
Replies
3
Views
899
Top