Finding local maxima and minima of a function given the graph