Finding local maxima from interpolated function

  • Context: Mathematica 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Function Local Maxima
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
member 428835
Hi PF!

I have data that I need to interpolate (don't want to go into details, but I HAVE to interpolate it). I'm trying to find the local maximas on a given domain. I've looked everywhere and still haven't been able to do it? Seems most people work with NDSolve, but I don't use that function.

Below is a simple code that illustrates my position. I'm trying to find the local maxima of ##f##.

data = Transpose[{Table[i, {i, 1, 30}], RandomReal[{0, 1}, {1, 30}] // Flatten}];
ListLinePlot[data]
f = Interpolation[data];
Plot[{f[x]}, {x, 1, 10}]
 
Physics news on Phys.org
Try
Code:
maxima = Table[FindMaximum[f[x], {x, i}], {i, 1, 9, .1}]
DeleteDuplicates[maxima,
Function[{a, b}, (Abs[a[[2, 1, 2]] - b[[2, 1, 2]]] < 0.1)]]

If you find that you are missing some maxima then you can always decrease the step size for your starting point.
 
Last edited:
  • Like
Likes   Reactions: member 428835