tye:

Yeah, I knew you weren't trying to find the curve for the sequences. The formula I gave was for minimizing the sum of the square of the difference between series 1 and A * series 2. That's so you could find A, the scaling factor you were looking for.

Having said that, however, when I tried to code it up, I found that I couldn't figure out how to express it as a curve fit problem. So instead I hacked up an iterative approach:

#!/usr/bin/perl -w use strict; use warnings; my @E1 = (2, 3.23, 7, 9, 11.3479); my @E2 = (3.3333, 1.433, 8.0577, 9.7344, 13.3377); my ($Alow, $Ahi, $Astep) = # (.5, 5, .1); # (0.8, 1.0, 0.025); # (0.85, 0.9, 0.005); (0.87, 0.88, 0.001); for (my $A=$Alow; $A <= $Ahi; $A+=$Astep) { printf "%7.4f %5.3f\n", $A, current_error($A); } sub current_error { my $A = shift; my $err=0; for (my $i=0; $i<@E1; ++$i) { my $t = $E1[$i] - $A*$E2[$i]; $err += $t*$t; } return $err; }

And the last run gave me:

Roboticus@Roboticus-PC ~ $ ./curvefit.pl 0.8700 5.091 0.8710 5.088 0.8720 5.086 0.8730 5.085 0.8740 5.084 0.8750 5.085 0.8760 5.085 0.8770 5.087 0.8780 5.089 0.8790 5.092 0.8800 5.096

So it looks like your multiplier is going to be roughly 0.874. If you need to consider a constant offset, you'll (obviously) have to nest in another loop to vary the constant as well. Since you didn't indicate the need for one, I didn't bother.

...roboticus


In reply to Re^3: Stumped with a math question in my Perl program (log scale) by roboticus
in thread Stumped with a math question in my Perl program by Anonymous Monk

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.