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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |