On an made up dataset the program runs fine. So the proper way to raise to the power is this:
n ^ 2 not this:
n**2;
here is the sample code:
#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::CurveFit;
my @X_data = qw(-20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -
+6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14);
my @Y_data = qw(1212 1095 984 879 780 687 600 519 444 375 312 255 204
+159 120 87 60 39 24 15 12 15 24 39 60 87 120 159 204 255 312 375 444
+519 600);
my $variable = 'x';
my $equation = 'r + m * x^2';
my @parameters = (
['r', '100'],
['m', '1'],
);
my $maxiter = '200';
my $square_residual = Algorithm::CurveFit->curve_fit(
formula => $equation, # may be a Math::Symbolic tree in
+stead
params => \@parameters,
variable => $variable,
xdata => \@X_data,
ydata => \@Y_data,
maximum_iterations => $maxiter,
);
print "$parameters[0][1] (should be 12)\t$parameters[1][1] (should be
+3)\n";
I'll try to do the more complex equation and I let you know how it went! Thanks.