Results 1 to 4 of 4

Math Help - Matlab bisection method

  1. #1
    Newbie
    Joined
    Apr 2010
    Posts
    23

    Matlab bisection method

    Please help me finish this problem

    Code:
    function bisect(n)
    
    syms x;
    
    f =  4 * x + 2;
    
    n = int32(n);
    
    err = 1;
    b=5;
    a=-5;
    
    while(b-a > err )
     m = (a+b)/2 ; 
       sa=  sign(feval(f,a)) ;
       sb = sign(feval(f,b)); 
       sm= sign(feval(f,m));
       
       if( sm == sa ) a=m;
       else b=m;
            
       end
    
    end
    The error message that i get is

    ??? Error using ==> feval
    Argument must contain a string or function_handle.

    Error in ==> bisect at 17
    sa= sign(feval(f,a)) ;

    Help me please.
    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 AUCC View Post
    Please help me finish this problem

    Code:
    function bisect(n)
    
    syms x;
    
    f =  4 * x + 2;
    
    n = int32(n);
    
    err = 1;
    b=5;
    a=-5;
    
    while(b-a > err )
     m = (a+b)/2 ; 
       sa=  sign(feval(f,a)) ;
       sb = sign(feval(f,b)); 
       sm= sign(feval(f,m));
       
       if( sm == sa ) a=m;
       else b=m;
            
       end
    
    end
    The error message that i get is

    ??? Error using ==> feval
    Argument must contain a string or function_handle.

    Error in ==> bisect at 17
    sa= sign(feval(f,a)) ;

    Help me please.
    f has to be a function of some kind, try:

    f=@(x) 4*x+2; % anonymous function definintion

    or:

    f=inline('4*x+2'); %inline function definition

    for the function definition.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2010
    Posts
    23
    Now i want to calculate the root's of a equation of degree 2

    Code:
    f=inline('x^2 + 2*x + 1');
    The root's are given by the value of m.

    So i get m=5 as the answer.

    Please help me.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by AUCC View Post
    Now i want to calculate the root's of a equation of degree 2

    Code:
    f=inline('x^2 + 2*x + 1');
    The root's are given by the value of m.

    So i get m=5 as the answer.

    Please help me.
    Without checking you code I can tell you that the bisection method will not work for your function. Bisection finds a point at which the function changes sign, but yours has a single root of multiplicity 2 (it does not change sign at such a root).

    In addition your two initial values do not correspond to different signs for the function value.

    CB
    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, 10:20 AM
  2. Bisection Method
    Posted in the Calculus Forum
    Replies: 1
    Last Post: February 22nd 2010, 12:07 AM
  3. Replies: 4
    Last Post: October 30th 2009, 01:29 PM
  4. MATLAB "bisection" method
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 5th 2009, 05:42 PM
  5. Bisection Method Help
    Posted in the Math Topics Forum
    Replies: 4
    Last Post: November 20th 2008, 03:41 PM

Search Tags


/mathhelpforum @mathhelpforum