1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Mar 29, 2010 #1
    Fixed Point iteration using matlab, whats wrong with my code??

    1. The problem statement, all variables and given/known data
    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..
    2. Relevant equations



    3. 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
     
  2. jcsd
  3. Mar 30, 2010 #2

    CEL

    User Avatar

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

    What kind of error are you getting?
     
  4. Mar 31, 2010 #3
    Re: Fixed Point iteration using matlab, whats wrong with my code??

    Could you comment your code? I can't quite figure out how this is supposed to perform fixed point iteration.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fixed Point iteration using matlab, whats wrong with my code?
  1. Fixed point iteration (Replies: 17)

Loading...