You can fit a curve of the form "Ax^2 + Bx + C = y" to the data. The package Statistics::Regression can be used to do it. (Make sure you edit Regression.pm to turn off DEBUGGING first):
use strict; use Statistics::Regression; my $reg= Statistics::Regression->new( 3, "quad regression", [ "const", + "X", "X^2" ] ); my @array = ('62.6', '62.8', '63', '63.3', '63.5', '63. +7', '64'); my @array2 = ('7.476', '7.5219', '7.5464', '7.5516', '7.5504', ' +7.5372', '7.518'); my $i; for $i (0..$#array) { my $x = $array[$i]; my $x2 = $x * $x; my $y = $array2[$i]; $reg->include($y, [1.0, $x, $x2]); } my $theta = $reg->theta(); print "Coefficients: ",join(",",@$theta),"\n"; my $c = $theta->[0]; my $b = $theta->[1]; my $a = $theta->[2]; print "\nComputed results:\n"; for $i (0..$#array) { my $x = $array[$i]; my $y = ($a*$x + $b)*$x + $c; my $ytrue = $array2[$i]; print "$x\t$y\t($ytrue)\n"; } # Solve for the derivative being 0. my $maxx = -$b/(2.0*$a); my $maxy = ($a*$maxx + $b)*$maxx + $c; print "\nPeak point:\n"; print "$maxx\t$maxy\n";
Don't count on a very accurate fit with so few data points. Once you have a quadratic equation, solve for the peak using "2Ax + B = 0". Again, don't count on great accuracy with this method.

Here is what I got:

Coefficients: -451.490758046837,14.4832720403469,-0.11423976795752 Computed results: 62.6 7.48383859766494 (7.476) 62.8 7.51535962535968 (7.5219) 63 7.53774147161789 (7.5464) 63.3 7.55417827581152 (7.5516) 63.5 7.55371216847811 (7.5504) 63.7 7.54410687970818 (7.5372) 64 7.51256298135968 (7.518) Peak point: 63.3897998012935 7.5550995057929

In reply to Re: mathsy question by tall_man
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.