% Problem M1.2.4
% Minimum of the quadratic x^2 + bx + c on the interval [L.R].

  b = input('Enter b:');
  c = input('Enter c:');
  L = input('Enter L:');
  R = input('Enter R) (L<=R:');
% Check for correct interval
  if L>R
     temp = R;
     R = L;
     L = temp;
  end

  xc = -b/2
  if xc < L
% Minimum of f is at L...
     minVal = L^2 + b*L + c;
  elseif R < xc
% Minimum of f is at R...
     minVal = R^2 + b*R + c;
  else
% The critical point xc is inside the interval
     minVal = c - (b/2)^2;
  end
  
  clc
  fprintf('Quadratic: x^2 + bx + c,  b = %5.2f, c = %5.2f\n',b,c)
  fprintf('Interval : [L,R], L = %5.2f, R = %5.2f\n',L,R)
  fprintf('xc       : %10.6f\n',xc)
  fprintf('Minimum  : %10.6f\n',minVal)

  