Finding local minima and maxima of a graph

James Hurley jhurley0305 at sbcglobal.net
Sun Dec 5 02:01:28 EST 2010


>
> Message: 26
> Date: Sat, 04 Dec 2010 12:56:05 -0500
> From: Bryan McCormick <bryan at deepfoo.com>
> To: use-livecode at lists.runrev.com
> Subject: Finding local minima and maxima of a graph
> Message-ID: <4CFA80B5.3090804 at deepfoo.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> I have a very large number of graphs to crunch through to find local
> minima and maxima. The data is regularly spaced, which eliminated one
> problem. I know too that the window value used has to be an adjustable
> variable as peak and trough significance may need to be found for a  
> wide
> range of time periods within the data set.
>
> I had thought of using a moving average to find a slope of zero and  
> then
> use an offset function to find the peak and trough in time.
>
> I've used stackoverflow to have a look and apparently the problem is a
> lot less trivial than I thought.
>
> Any suggestions for fitting to a function, using the graphing  
> functions
> in rev, etc would be most welcome.
>
>
>

Bryan,

If the data is "well behaved" you might try just finding out where the  
derivative (slope) changes sign. For example:

function MinMax tList
    put line 1 of tList into yOld
    put 0 into dyOld
    repeat for each line yNew in tList
       put yNew - yOld into dy
       put dy * dyOld into tChange
       if tChange  < 0 or tChange = 0 then
          put yNew & cr after tExreema
       end if
       put ynew into yOld
       put dy into dyOld
    end repeat
    return tExreema
end MinMax





More information about the Use-livecode mailing list