Finding local minima and maxima of a graph

James Hurley jhurley0305 at sbcglobal.net
Sun Dec 5 11:40:35 EST 2010


Brian,

> Jonathan, Jerry, et al
>  As to the number of potential observations. Thousands of series,  
> 10s to hundreds of thousands of observations per series at a  
> minimum. Possibly millions. So computational efficiency isn't a  
> luxury, it is a requirement.
> Brian

The following method is fairly efficient. The process, on my slow Mac  
Mini, take 2 seconds to process one million data points.

on mouseUp
    put .1 into tAngle
    --Create one million data points
    repeat 1000000 times
       put sin(tAngle*pi/180) & cr after tempList
       add 5 to tAngle
    end repeat
    --Now find the minima and maxima
    put the sec into tStartTime
    put MinMax(tempList) into field 1
    put the sec - tStartTime into msg box
    beep
end mouseUp

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