Finding the maximum or minimum value and the range of a function