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.


In reply to Re: Re: mathsy question by no_slogan
in thread mathsy question: finding max of curve from discrete points by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.