Possible Duplicate:
Local max/min of Mathematica data sets
If I have a continuous function f (for example f = Sin[x]), I can find the local extrema in the vicinity of $x = x_0$ using FindMinimum[f, {x, x0}] and FindMaximum[f, {x, x0}]. For example:
FindMinimum[Sin[x], {x, Pi}]
FindMaximum[Sin[x], {x, Pi}]
(* {-1., {x -> 4.71239}} *)
(* {1., {x -> 1.5708}} *)
However, what if I have a discrete function -- a function described by a list of points? This comes up frequently when working with data from experiments. For example, suppose I have the following discrete function described by x and f:
x = Range[0, 2 Pi, 0.1];
f = Sin[x];
Show[{
Plot[Sin[x], {x, 0, 2 Pi}, PlotRange -> All],
ListPlot[Transpose[{x, f}]]

How can I find the local extrema of the data defined by Transpose[{x, f}]?
I could interpolate the data and then use FindMinimum and FindMaximum:
interp = Interpolation[Transpose[{x, f}]]
FindMinimum[interp[x], {x, Pi}]
FindMaximum[interp[x], {x, Pi}]
(* InterpolatingFunction[{{0., 6.2}}, <>] *)
(* {-0.999999, {{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.,
1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2., 2.1, 2.2, 2.3,
2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3., 3.1, 3.2, 3.3, 3.4, 3.5, 3.6,
3.7, 3.8, 3.9, 4., 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9,
5., 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6., 6.1, 6.2} ->
4.71232}} *)
(* {0.999998, {{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1,
1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2., 2.1, 2.2, 2.3, 2.4,
2.5, 2.6, 2.7, 2.8, 2.9, 3., 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7,
3.8, 3.9, 4., 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.,
5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6., 6.1, 6.2} ->
1.57084}} *)
But is there any way to find the local extrema without using Interpolation? Thanks for your time.



Differences[f]and locate where they change sign. – b.gatessucks Nov 11 '12 at 17:46MinandMax. – VLC Nov 11 '12 at 17:49