If you have an approximation of a function given by a serie of points on a vector, how to find it's maximums and minimums?
Maximums and minimums can be found with the roots of the derivative of the function. This could be done with the diff(y) function. Is there an easy way to get the indexes of the zeroes of diff(y)? And interpolated indexes?
Thanks for your help.
What I have found so far is this:
The indexes are not interpolated with that solution. Diff making the difference of contiguous values, the size of the vector is decreased by one. As this function is applied twice, the index position may be wrong by up to a couple of indexes I guess.
diff(y)<0 // negative y'=T, positive y'=F
diff(diff(y)<0) // sign change of y' =1 or -1, otherwise 0
find(diff(diff(y)<0)) //return indexes of sign change of y' <mapquest driving directions>