function [x,t,e] = mullers(f,p0,p1,p2,TOL,N)

    tic;
    i = 1;
    while (i<=N)

        x1=p0;
        x2=p1;
        x3=p2;
        y1=f(x1);
        y2=f(x2);
        y3=f(x3);

        % I could not for the life of me get the equations to work, did some searching on the internet and found another method to fit a parabola to 3 points using matrices
        A = [x1^2, x1, 1; x2^2, x2, 1; x3^2, x3, 1];

        % Solve the least squares problem
        coeffs = A \ [y1; y2; y3];

        % Grab the coefficients
        a = coeffs(1);
        b = coeffs(2);
        c = coeffs(3);

        if (b >= 0)
            r1 = (-b - sqrt(b*b - 4*a*c))/(2*a);
            r2 = (2*c)/(-b - sqrt(b*b - 4*a*c));

            if (abs(-b - sqrt(b*b - 4*a*c)) > abs(-b + sqrt(b*b - 4*a*c)))
                p3 = r2;
            else
                p3 = r1;
            end

        else
            r1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
            r2 = (2*c)/(-b + sqrt(b*b - 4*a*c));

            if (abs(-b + sqrt(b*b - 4*a*c)) > abs(-b - sqrt(b*b - 4*a*c)))
                p3 = r2;
            else
                p3 = r1;
            end

        end

        p0 = p1;
        p1 = p2;
        p2 = p3;

        if (abs(p2 - p1) < TOL)
            x = p3;
            t = toc;
            e = 3*i;
            return;
        end

        i = i + 1;
    end

    x = NaN;
    t = NaN;
    e = NaN;
end
