function p6
    disp('----------------------')
    disp('Part a)')
    disp('----------------------')
    bisect(-2, -1, @f_part_a)
    bisect(1, 2, @f_part_a)

    disp('----------------------')
    disp('Part b)')
    disp('----------------------')

    bisect(-4, -3, @f_part_b)
    bisect(0, 1, @f_part_b)
    bisect(3, 4, @f_part_b)

    disp('----------------------')
    disp('Part c)')
    disp('----------------------')

    bisect(0.8, 1, @f_part_c)
    bisect(1, 1.2, @f_part_c)
end

function bisect(a, b, f)
    tol = 1e-6

    fa = f(a);
    fb = f(b);

    disp('Interval at start:')
    a
    b

    % intermediate value theorem must guarantee existence of a
    % zero in (a,b).
    if (fa*fb > 0)
      error('Potentially no zero in search interval.')
    end

    while (abs(b-a) > tol)
        c = (a+b)/2.;
        fc = f(c);

        if (fc*fa <= 0)
            b = c;
            fb = fc;
        else
            a = c;
            fa = fc;
        end
    end

    disp('Final Interval:')
    a
    b
end

function y = f_part_a(x) 
    y = exp(x)+x^2-x-4;
end
function y = f_part_b(x) 
    y = x^3-x^2-10*x+7;
end
function y = f_part_c(x) 
    y = 1.05 - 1.04*x+log(x);
end
