in reply to mathsy question: finding max of curve from discrete points

I had a similar problem some time ago but it was related to goal seeking. If you have a function then Math::Brent will help you find a solution to it.

Math::Polynomial has methods of creating such functions.

Hope it helps
UnderMine

Replies are listed 'Best First'.
Re: Re: mathsy question
by no_slogan (Deacon) on May 07, 2003 at 15:13 UTC
    Math::Polynomial has methods of creating such functions.

    Specifically, Math::Polynomial::interpolate. It may not be such a good idea to fit your entire data set with a polynomial and then maximize it. For one, it can be slow. For two, the high-order polynomials found by fitting many points show a lot of "stiffness" which makes them bad for fitting unsmooth functions (where "smooth" is defined as "similar to a polynomial") -- whether this is a problem for you depends on your data set. Be careful with Brent's method, also, because it can get stuck in a local maximum.

    For quadratic interpolation, you can take the maximum data point and its two neighbors and fit them with Math::Polynomial. You can easily find the maximum of the resulting parabola by setting the derivative equal to zero. No need to use Math::Brent.

    Update: I realized that I was confused between regression and interpolation right after hitting submit. Quadratic regression, as demontrated by tall_man, is probably a good idea if your data is all fairly close to the peak.