doozy has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expecting a 100 solutions, getting just 1
by moritz (Cardinal) on Apr 17, 2012 at 08:35 UTC | |
by doozy (Initiate) on Apr 17, 2012 at 08:58 UTC | |
by moritz (Cardinal) on Apr 17, 2012 at 09:10 UTC | |
by doozy (Initiate) on Apr 17, 2012 at 09:58 UTC | |
|
Re: Expecting a 100 solutions, getting just 1
by Anonymous Monk on Apr 17, 2012 at 08:44 UTC | |
|
Re: Expecting a 100 solutions, getting just 1
by brx (Pilgrim) on Apr 17, 2012 at 09:33 UTC |