% Find min of q(x)=x^2+bx+c given b,c and random L,R

b= 2; c= -1.5; % coefficients of q(x)
L= rand*10 - 8; % left end of interval, random in (-8,2)
R= L + 1 + rand*10; % right end of interval, random in (-7,13)

xc = -b/2; % critical value

if (L<=xc && xc<=R)
% min is at xc
qMin= xc^2 + b*xc + c;
else
% min is at L or R
if xc < L
qMin= L^2 + b*L + c;
else
qMin= R^2 + b*R + c;
end
end

disp('Quadratic function q(x) = x^2 + bx + c')
fprintf(' b=%.2f c=%.2f\n', b,c)
fprintf('The minimum value in [%.2f,%.2f] is %.4f\n', L,R,qMin)