%  quad_min_max.m
%  Determine the minimum and maximum of a quadratric function
%  over the whole real line.
%
a = input ( '  Enter coefficient A: ' );
b = input ( '  Enter coefficient B: ' );
c = input ( '  Enter coefficient C: ' );
%
%  If A is 0, then we have a linear equation Y = B * X + C.
%  The min is -Inf, the max is +Inf...unless B is 0!
%
  if ( a == 0.0 )

    if ( b == 0.0 )
      qmin = c;
      qmax = c;
    else
      qmin = -Inf;
      qmax = +Inf;
    end

  elseif ( a < 0.0 )

    qmin = -Inf;
    qmax = - b / ( 2 * a );

  else

    qmin = - b / ( 2 * a );
    qmax = + Inf;

  end

  fprintf ( '  Q(X) = %g x^2 + %g x + %g\n', a, b, c );
  fprintf ( '  Minimum value is %g\n', qmin );
  fprintf ( '  Maximum value is %g\n', qmax );
