#!/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 substitute 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";