Results 1 to 3 of 3

Math Help - fixed point iteration ,help needed

  1. #1
    Newbie
    Joined
    Sep 2008
    Posts
    10

    fixed point iteration ,help needed

    Hi i m trying to write a script file in matlab,which takes as input a function f(x) and an initial estimate of the root x0 and outputs the true root of the function f(x). This is th Fixed Point iteration method in matlab.

    After i have written my script,i have to test it with a function g(x)=1+1/x at x0
    I have already created a script file but i m not sure where i am going wrong.

    My script File is:

    function x = fixed(g,x0,tol)
    x0=2;
    n=1;
    x(1)=x0
    x(2)=feval(g,x0)
    while abs(x(n-1)-x(n))>tol
    k=n-1
    x(n)=feval(g,k);
    n=n+1;
    end
    return

    can anyone tell me,wht is wrong with this script file. or anyone provide with with an alternate matlab code for fixed point iteration method.
    any sort of help will be appreciated . thnks.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by mithilesh View Post
    Hi i m trying to write a script file in matlab,which takes as input a function f(x) and an initial estimate of the root x0 and outputs the true root of the function f(x). This is th Fixed Point iteration method in matlab.

    After i have written my script,i have to test it with a function g(x)=1+1/x at x0
    I have already created a script file but i m not sure where i am going wrong.

    My script File is:

    function x = fixed(g,x0,tol)
    x0=2;
    n=1;
    x(1)=x0
    x(2)=feval(g,x0)
    while abs(x(n-1)-x(n))>tol
    k=n-1
    x(n)=feval(g,k);
    n=n+1;
    end
    return

    can anyone tell me,wht is wrong with this script file. or anyone provide with with an alternate matlab code for fixed point iteration method.
    any sort of help will be appreciated . thnks.
    Try:

    Code:
    function x = fixed(g,x0,tol)
     
    xx=x0;
    err=1e6;
     
    while err>tol
      x=feval(g,xx);
      err=abs(xx-x);
      xx=x;
    end
    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2008
    Posts
    10
    i get it now,thhknks for ur help buddy. appreciate it.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Fixed point iteration help
    Posted in the Advanced Math Topics Forum
    Replies: 8
    Last Post: November 8th 2011, 11:19 AM
  2. Fixed Point Iteration
    Posted in the Algebra Forum
    Replies: 2
    Last Post: November 10th 2010, 10:14 AM
  3. Fixed point iteration
    Posted in the Differential Geometry Forum
    Replies: 13
    Last Post: October 21st 2010, 03:36 AM
  4. Fixed point iteration
    Posted in the Advanced Math Topics Forum
    Replies: 0
    Last Post: February 2nd 2010, 07:30 AM
  5. Fixed Point Iteration
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: November 12th 2009, 12:40 PM

Search Tags


/mathhelpforum @mathhelpforum