Notices
Results 1 to 5 of 5

Thread: Root finding algorithms. Bisection method and False Position

  1. #1 Root finding algorithms. Bisection method and False Position 
    Forum Masters Degree organic god's Avatar
    Join Date
    Feb 2008
    Location
    London
    Posts
    567
    Firstly i won't put the method down for both methods as I am really asking a question and so whoever answers it will be familiar with the routine.

    Basically I wrote 2 programmes one for a bisection method and one for a false position method which are both used to find roots for simple 1d problems.
    i.e roots of y = f(x)

    to me it seems that the false position method would be better i.e. converges to the root more rapidly as it takes into account the relative magnitudes of f(b) and f(a) unlike bisection which just uses the midpoint of a and b, where [a,b] is the interval over which the root occurs.

    However when i ran my programme the false position method actually converges slower to the root =S. can anyone explain this to me??

    N.B. both these methods are poor so this point is rather moot but it still interests me.

    EDIT**If anyone wants the programme it is a matlab m-file so just pm me and i will email it to you.**


    everything is mathematical.
    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman holysword's Avatar
    Join Date
    Apr 2008
    Posts
    41
    I think that its possible to create an example in which one method converges faster than the other, or at least at the same time... just a matter on how the function looks like, isn't it?

    In any case, maybe it would help if you post your Matlab prototype here.


    "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium"
    Yeshua Ha Mashiach
    Reply With Quote  
     

  4. #3  
    Forum Ph.D.
    Join Date
    Jul 2008
    Location
    New York State
    Posts
    991
    Bisection takes about the same time no matter what the shape of the function is. False position works better if the derivative of the function doesn't vary too much over the interval in question. However if it varies widely, it could take a lot longer.
    Reply With Quote  
     

  5. #4  
    Forum Masters Degree organic god's Avatar
    Join Date
    Feb 2008
    Location
    London
    Posts
    567
    function p = bisection(a,b,tol)
    x = sym('x');
    y = %insert function y = f(x);
    p = a+b/2;
    yp = subs(y,x,p);
    ite = 1;
    while abs(yp) > tol
    ya = subs(y,x,a);
    yb = subs(y,x,b);
    yp = subs(y,x,p);
    valmat(ite, = [a,b,p,ya,yb,yp];
    if (ya*yp)<0
    b = p;
    else
    a = p;
    end
    p = (a+b)/2;
    ite = ite+1;
    end
    valmat
    p
    ite

    function p = false_position(a,b,tol)
    x = sym('x');
    y = % insert y as a funcion of x
    ya = subs(y,x,a);
    yb = subs(y,x,b);
    p = ((yb*a)-(ya*b))/(yb-ya);
    yp = subs(y,x,p);
    ite = 1;
    valmat = [];
    while abs(yp)>tol
    ya = subs(y,x,a);
    yb = subs(y,x,b);
    yp = subs(y,x,p);
    valmat(ite, = [a,b,p,ya,yb,yp];
    if (ya*yp) < 0
    b = p;
    else
    a = p;
    end
    p = ((yb*a)-(ya*b))/(yb-ya);
    ite = ite+1;
    end
    valmat
    ite
    p

    save these as m-files, and then use matlab command window to find roots for y in the interval a,b

    i ran it for some different functions and yeh the spped of convergence depends on the function and the interval, i thought it false position would be quicker for all f though
    everything is mathematical.
    Reply With Quote  
     

  6. #5  
    Forum Masters Degree organic god's Avatar
    Join Date
    Feb 2008
    Location
    London
    Posts
    567
    in the above post smily face is meant to be colon).

    also if anyone here is familiar with matlab, could they tell me how to have function p = bisection(f(x),a,b,tol)

    allowing the user to define f(x) in the command window, rather than having to go into the m-file to change f(x)
    everything is mathematical.
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •