Thanks for the pointer to the PDL package, tye. Here is the polynomial fit I did above converted to use piddles. But as you say, polynomials may not be the best thing to use.
use strict; use PDL::LiteF; use PDL::Fit::Polynomial; my $xp = pdl (62.6, 62.8, 63, 63.3, 63.5, 63.7, 64) +; my $yp = pdl (7.476, 7.5219, 7.5464, 7.5516, 7.5504, 7.5372, 7. +518); my ($yfit,$coeffs) = fitpoly1d($xp,$yp,3); my $diffp = $yp - $yfit; my @theta = list $coeffs; print "Coefficients: ",join(",",@theta),"\n"; my $c = $theta[0]; my $b = $theta[1]; my $a = $theta[2]; print "\nComputed results:\n"; my $xtop = $xp->nelem - 1; for my $i (0..$xtop) { my $x = at($xp,$i); my $y = at($yfit,$i); my $ytrue = at($yp,$i); my $diff = at($diffp,$i); print "$x\t$y\t($ytrue)\t$diff\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";

In reply to Re: Re: mathsy question: finding max of curve from discrete points (two steps) 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.