SeigePerlous has asked for the wisdom of the Perl Monks concerning the following question:

Maybe I'm just so new to Perl, or I'm not looking in the right place, but I can't find anything that states the organization of the fitted values returned from fitpoly1d in this module. I figured it was an array (vector) but pp tells me otherwise...
pp($yFit); yFit: bless(do{\(my $o = 100732500)}, "PDL") Argument "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." + isn't numeric in multiplication (*) at Y:\GUI\..\ CommonModules/UnitConverter.pm line 185, <GEN1> line 1617.
What exactly does fitpoly1d return and how do I simply get the fitted values? Thanks!

Replies are listed 'Best First'.
Re: PDL::Fit::Polynomial return values
by zentara (Cardinal) on Oct 14, 2011 at 18:25 UTC
    Your example code dosn't show much, here is an example pulled from the PDL maillist. See also output from fitpoly1d
    #!/usr/bin/perl use PDL; use PDL::MATH; use PDL::Fit::Polynomial; my $xdata = sequence float, 16; my $ydata = sequence float, 16; my $i = 0; while ($i < 16) { $xdata[$i] = $i; $ydata[$i] = $i * $i; print "i ", $i, " x ", $xdata[$i], " y ", $ydata[$i], "\n"; $i++; } ($yfit, $coeffs) = fitpoly1d $xdata, $ydata, 3; print "Fit complete with coeffs ", $coeffs, "\n"; print "Fitted values ", $yfit, "\n"; $i = 0; while ($i < 16) { print "i ", $i, " yfit ", $yfit[$i], "\n"; $i++; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh