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.

In reply to Re^4: fitting double lognormal distribution on a dataset by sdani
in thread fitting double lognormal distribution on a dataset by sdani

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.