Re: How can I find Max and Mins of array by seeing which point's derivative is closest to 0 [message #61593] |
Tue, 22 July 2008 13:34 |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
<lukedimperio@yahoo.com> wrote in message
news:cbf7303c-1507-402f-94b3-37ccf49b4021@c65g2000hsa.google groups.com...
> Fellow programmers,
>
> I have produce several ~ shaped plots in IDL and would like to
> find the Max and Min of the crest and trough respectively. Yet, the
> points of the ~ reach above and below the tops and bottoms of the
> curves trough and crest. So I thought I would locate them by find
> where the derivative of the curve equalled zero, right? Yet, it was an
> array so the wasn't an exact 0. So, I figured I would attempt to find
> the minimum of all the positive array slopes(derivatives) and this
> would be a point right after a minimum or before a maximum. Or you
> could do it by finding the maximum of all the negative array slopes
> and that would correspond to a point just before a minimum or right
> after a maximum. It didn't really matter if I was off by one point
> because there were so many points in the array. Here's the fun part
> though; I tried several different lines of codes mostly include where
> commands finding each time the max and min would be at the end and NOT
> at the top of the crest or bottom of the trough like I wanted them to
> be!
>
> In case the squiggles aren't visible enough the plot is a fit by a 3rd
> order polynomial, sort of like a sideways s. Not really this S though
> because doesn't really look like a function.
>
> Anyway, please help and please feel free to email me
> lukedimperio@yahoo.com
>
> Luke D'Imperio
> SUNY Oneonta
>
> P.S. I'm getting suspicious of a invisible zero at the beginning of
> the curve. Don't let it bother you too much though.
Find each local maxima (minima), then take the three points (the one
before it, that one, and the one after it) and fit a parabola.
y = a + bx + cx^2
Calculate the peak position and value from the best fit equation for the
parabola.
The derivative is
b + 2cx = 0
so x = b/2c.
The peak is y(b/2c)
Just make sure the middle peak is greater than the neighbor
points and you are all set.
Cheers,
bob
|
|
|