Finds the extrema of the function