xralier
1/20/2018 - 4:03 PM

Bisection Method in Mat Lab

myFunction = @ (x) 5*x^3 - 5*x^2 + 6*x -2 ; % anonymous fucntion to specify our equation

% initial values
x_low = 0 ;
x_up = 1;

x_mid = (x_low+x_up)/2; % calculating mid 

while abs (myFunction(x_mid)) > 0.01  % make this 0.01 value more small to get more accurate result 
    if myFunction(x_mid) < 0   % if the sign is (-)
        x_low = x_mid ;
    else                        % else , the sign is (+)
        x_up = x_mid;
    end
    
    x_mid = (x_low+x_up)/2;
    
end

disp (x_mid)  % displaying root value