%
% File name: bisection.m
% Author: Suh-Yuh Yang at NCU
% Date: September 21, 2018   
%
clear all;
format long 
a = -4.0;    
b = -3.0;
M = 100;
delta = 10^(-3);
epsilon = 10^(-5);
%
%
%
u = exp(a) - sin(a);
v = exp(b) - sin(b);
e = b - a; 
%
%
%
if sign(u) == sign(v)  
    display('The initial interval is not suitable!')
    break
end    
for k=1:1:M
    e  = e/2;
    c  = a+e;
    w = exp(c) - sin(c);
    [k, c, w]
    if abs(e) < delta & abs(w) < epsilon
        display('The approximate solution is obtained')  
        [k, c, w]
        break 
    end
    if sign(w) ~= sign(u)
        b = c;
        v = w;
    else
        a = c;
        u = w;        
    end
end
