Message Boards Message Boards

[✓] Find first local minima?

GROUPS:

Dear All,

I have a list as following (for example)

data = {10,8,7,6,5,3,4,5,2,3,2,1,0}

The first local minima is 3.

How can I find this value in Mathematica ?

Thank so much for your help.

POSTED BY: M.A. Ghorbani
Answer
10 days ago

Would this work?

-FindPeaks[-data, 0, 0, -Infinity][[1, 2]]

Cheers,

Marco

POSTED BY: Marco Thiel
Answer
10 days ago

Dear Marco,

That's great.

How can I find the position of this value at the list?

Regards,

POSTED BY: M.A. Ghorbani
Answer
10 days ago

Try:

Position[data, 3]
(*  {{6}, {10}} *)

Regards, Mariusz

POSTED BY: Mariusz Iwaniuk
Answer
10 days ago

Hi,

don’t use the “2•. You will also need to multiply the x-value by -1.

Cheers,

Marco

POSTED BY: Marco Thiel
Answer
10 days ago

Dear Marco, Mariusz

Thanks again.

I used your solution for my real data. Unfortunately the result shows { }. Please see the attached file.

Regards,

Attachments:
POSTED BY: M.A. Ghorbani
Answer
10 days ago

You need write a pattern using Condition to force searching based on numerical equality:

See here (Position->Possible Issues) for more information.

Regards, Mariusz

Attachments:
POSTED BY: Mariusz Iwaniuk
Answer
10 days ago

I agree that the Position function is a viable option, but keep in mind that FindPeaks gives the x-position of the maxima by default. so something like:

sol = {1, -1}*FindPeaks[-m, 0, 0, -Infinity][[1]]

would give you x and y position of the first minimum. If you use

sol = {1, -1}*# & /@ FindPeaks[-m, 0, 0, -Infinity]

you get the same for all minima. Using Mariusz' notation:

ListPlot[CorrelationFunction[data, {100}], 
 TicksStyle -> {{FontSize -> 16, Orange}, {FontSize -> 22, Green}}, 
 PlotRange -> All, AxesLabel -> {Style[x, Large], Style[y, Large]}, 
 Epilog -> {PointSize[0.01], Red, Point /@ sol}]

gives:

enter image description here

Cheers,

Marco

POSTED BY: Marco Thiel
Answer
10 days ago

What about an "old fashioned" way without sophisticated "modern" functions?

data = {10, 8, 7, 6, 5, 3, 4, 5, 2, 3, 2, 1, 0};

min = data[[1]];
Catch[
 Do[
  If[data[[i]] < min, min = data[[i]], Throw[{i - 1, min}]],
  {i, 2, Length[data]}]]

{6, 3}
POSTED BY: Hans Dolhaine
Answer
10 days ago

Group Abstract Group Abstract