Polynomial regression: Difference between revisions

→‎{{header|Perl}}: DOES NOT WORK - inserted a caution and proof to save other future pain.
(→‎{{header|Perl}}: DOES NOT WORK - inserted a caution and proof to save other future pain.)
Line 1,303:
 
=={{header|Perl}}==
 
## CAUTION - THE BELOW SCRIPT DOES NOT WORK. Example:-
# $ perl polyfit.pl
# Please enter the values for the x coordinates, each delimited by a space. (Ex: 0 1 2 3)
# 0 1 2 3 4 5 6 7 8 9
# Please enter the values for the y coordinates, each delimited by a space. (Ex: 0 1 2 3)
# 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0
# An approximating polynomial for your dataset is -1x^7 + 12x^6 + -71x^5 + 259x^4 + -555x^3 + 630x^2 + -274x + 3.
##
# perl -e 'foreach $x (0..9) {print -1*$x**7 + 12*$x**6 + -71*$x**5 + 259*$x**4 + -555*$x**3 + 630*$x**2 + -274*$x + 3; print " ";}'
# 3 3 47 153 -165 -5617 -35337 -144603 -463117 -1254885 [cnd@mac Downloads]$
## (above is WRONG)
# perl -e 'foreach $x (0..9) {print 1.0848*$x**2+10.3552*$x-0.6164; print " ";}'
# -0.6164 10.8236 24.4332 40.2124 58.1612 78.2796 100.5676 125.0252 151.6524 180.4492
## (working polynomial above is from another implementation on this page)
##
 
This script depends on the <tt>Math::MatrixReal</tt> CPAN module to compute matrix determinants.
<lang Perl>use strict;
Anonymous user