Results 1 to 5 of 5

Math Help - Mathlab help Bisection Method

  1. #1
    Newbie
    Joined
    Apr 2008
    Posts
    12

    Mathlab help Bisection Method

    Hello, I am trying to figure out how to use the bisection methode to do this problem and matlab, but I keep having problems with inputing my formula. Here is it below:

    My formula: ln(x+1)+tan(2x) = 0

    Here is my bisection method m-file:

    function ww=bisect(f,a0,b0,tol)
    %a and b are the end of the interval, c is the midpoint, n is iterations
    %tol is our tolerence which is our stopping criteria
    a=a0; b=b0;
    sfb = sign(feval(f,b));
    width = b-a;
    n=0;
    while width > tol
    n=n+1;
    width = width/2;
    x = a + width;
    sfx = sign(feval(f,x));
    if sfx ==0
    a = x; b = x;
    return
    elseif sfx == sfb, b = x;
    else a = x; end
    end
    c=0.5*(a+b);
    ww=[a,b,c,n];
    return

    Could someone please tell me who to apply the above formula so that the bisection method is performed then I have to show the graph? I am new to matlab and it will not read the party in when I put in y = ln(x+1)+tan(2x) it keeps saying error.
    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 Dream View Post
    Hello, I am trying to figure out how to use the bisection methode to do this problem and matlab, but I keep having problems with inputing my formula. Here is it below:

    My formula: ln(x+1)+tan(2x) = 0

    Here is my bisection method m-file:

    function ww=bisect(f,a0,b0,tol)
    %a and b are the end of the interval, c is the midpoint, n is iterations
    %tol is our tolerence which is our stopping criteria
    a=a0; b=b0;
    sfb = sign(feval(f,b));
    width = b-a;
    n=0;
    while width > tol
    n=n+1;
    width = width/2;
    x = a + width;
    sfx = sign(feval(f,x));
    if sfx ==0
    a = x; b = x; return
    elseif sfx == sfb, b = x;
    else a = x; end
    end
    c=0.5*(a+b);
    ww=[a,b,c,n];
    return

    Could someone please tell me who to apply the above formula so that the bisection method is performed then I have to show the graph? I am new to matlab and it will not read the party in when I put in y = ln(x+1)+tan(2x) it keeps saying error.
    Well the following seems to work for me:

    Code:
    
    
     bisect('ff',0,10,0.001)
    ans =
        2.6831    2.6837    2.6834   14.0000
    
    where ff.m is on the search path and defined the function:

    Code:
    function rv=ff(x)
      rv=log(x+1)+tan(2*x);
    But this is on a very old version of Matlab so this may no longer be the prefered format for passing a function as an argument to a function.

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Dream View Post
    in when I put in y = ln(x+1)+tan(2x) it keeps saying error.
    Unless they have changed a few basic things while I was looking the other way (entirly possible as there are at least four Matlab updates sitting in my bookshelves at work that I have never installed or read the notes of) natural log is "log" not "ln" and you have to have a multiply operator between the 2 and the x. So the correct form of the function you want is:

    log(x)+tan(2*x)

    RonL
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Apr 2008
    Posts
    12

    Bisection method

    Hey try the problem with the initial interval a0=-1, and b0=1 with the following equation using the same bisection method m-file. I am having problems with it acknowledging the sign. Maybe you can figure it out. Here is the function to be used below:

    6((e^(x) -x) - 2x^(3) - 3x^(2) -6 between -1 and 1

    use the bisection method for this function.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Dream View Post
    Hey try the problem with the initial interval a0=-1, and b0=1 with the following equation using the same bisection method m-file. I am having problems with it acknowledging the sign. Maybe you can figure it out. Here is the function to be used below:

    6((e^(x) -x) - 2x^(3) - 3x^(2) -6 between -1 and 1

    use the bisection method for this function.
    First you have to code it right:

    6*(exp(x)-x) - 2*x^3 -3*x^2-6.

    Now this has a root at x=0, but the bisection method has trouble finding it accurately since this is zero (that is its value is down in the rounding noise) over an interval of length several* 10^{-6}.

    However the bisection method should find a root at ~+/- 10^-6. Except when I run your code it returns nothing, presumably it does not recognise this as convergence.

    RonL
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. bisection method
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 25th 2010, 09:20 AM
  2. Bisection method
    Posted in the Calculus Forum
    Replies: 3
    Last Post: February 24th 2010, 04:31 AM
  3. More Bisection MEthod
    Posted in the Calculus Forum
    Replies: 0
    Last Post: September 27th 2009, 11:15 PM
  4. Bisection Method
    Posted in the Calculus Forum
    Replies: 0
    Last Post: September 27th 2009, 07:12 PM
  5. mathlab--jacobi iteration method
    Posted in the Math Software Forum
    Replies: 6
    Last Post: December 10th 2008, 03:07 AM

Search Tags


/mathhelpforum @mathhelpforum