how to find local maximum and minimum values