finding max and min of cubic function