function [xmin, fmin] = quadmin(b,c,L,R)
% Finds the minimum point and minimum value of x^2 + bx + c 
% on the interval [L,R]

% swap endpoints if left one is greater than right one
if L > R
   temp=L;
   L=R;
   R=temp;
end

% critical point of the quadratic
xc = -b/2;

if xc < L
    % minimum at left endpoint
    xmin = L;
    fmin = L^2 + b*L + c;
elseif xc >= L && xc <= R
    % minimum at critical point
    xmin = xc;
    fmin = c - (b/2)^2;
else
    % minimum at the right endpoint
    xmin = R;
    fmin = R^2 + b*R + c;
end

end
