Hello Monks- I have the following script to generate a 100 trial solutions of A and B, uniformly distributed between 0 and A_max and 0 and B_max, respectively. I want to choose a trial pair of A and B which will minimize a certain error term. What I don't understand is how to "store" the 10000 trial solution pairs so they can be referred to by the script. Also, if I wanted to print the 100 solutions, e.g. for A, how can that be done? I only get 1 solution for A when I run just the t and A loops and print $A. Here's the (incomplete) code, I put a space between the lines to help readability:

#!/usr/bin/perl $A_max = 1e-05, $B_max = 1e-04, $t_max = 200, $z_best = 1e+12; for ($t=0; $t<=$t_max; $t++) { for ($A=0; $A<=$A_max; $A+=$A_max/100) { for ($B=0; $B<=$B_max; $B+=$B_max/100) { #something here that should refer to $i_max; $i_max = 10000 because I expect 10000 pairs of A and B solution pairs. #somehow use the 10000 trial solution pairs of $A and $B to sub +stitute into the equation, $er_max = |A| + |B|. #set $er_max = $z, corresponding to the error calculated for each + trial solution pair. for ($i=0; $i<$i_max; $i++) { if ($z < $z_best) { $z_best = $z; $A_best = $A; $B_best = $B; } } } } } print "$A = $A_best\n"; print "$B = $B_best\n";

In reply to Expecting a 100 solutions, getting just 1 by doozy

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.