Finding the maximum or minimum of a quadratic function