How can I get this code to substitute the new values of lambda_max and cro_max (at the end of the code) as initial values, and be able to print them for t = 0, t = 1, t = 2 etc. **update** Thank you everyone! Made some stupid mistakes because of being tired, sheeessh. Anyways, if there's a quick/easy way to take the values of cro_next and lambda_next and feed them into the loop all over so I don't have to do it manually, I would appreciate that. I want lambda_next and cro_next values for t = 1, t = 2, ... t = 200. Thanks again!

#!/usr/bin/perl $lambda_max = 1e-07; $cro_max = 0; $dna_max = 1e-07; $K1 = 1e+08; $K3 = 1e+05; $KC = 1e+08; $ks = 20; $kdeg = 0.1; $t_max = 200; for ($t=0; $t<=$t_max; $t++) { $error_best = 1e+12; for ($lambda=0; $lambda<$lambda_max; $lambda+=$lambda_max/100) + { for ($cro=0; $cro<$cro_max; $cro+=$cro_max/100) { $c1 = 1 + $K1 * $lambda + $K1**2 * $lambda**2; $c3 = 1 + $K3 * $lambda + $KC * $cro; $c = $dna_max / (($c1) * ($c3)); $r2 = $c * $K1 * $lambda; $r3 = $c * $K3 * $lambda; $r4 = $c * $K1**2 * $lambda**2; $r5 = $c * $K1 * $K3 * $lambda**2; $r6 = $c * $K1**2 * $K3 * $lambda**3; $r7 = $c * $KC * $cro; $r8 = $c * $K1 * $KC * $lambda * $cro; $r9 = $c * $K1**2 * $KC * $lambda**2 * $cro; $lamOR1 = $r2 + $r4 + $r5 + $r6 + $r8 + $r9; # $lamOR2 = $r4 + $r6 + $r9; # eq. 6 $lamOR3 = $r3 + $r5 + $r6; # eq. 6 $croOR3 = $r7 + $r8 + $r9; # eq. 6 $x1 = $lambda + $lamOR1 + $lamOR2 + $lamOR3 - $lambda_max; $x2 = $cro + $croOR3 - $cro_max; $error = abs($x1) + abs($x2); if ($error < $error_best) { $error_best = $error; $lambda_best = $lambda; $cro_best = $cro; } } } $c1_best = 1 + $K1 * $lambda + $K1**2 * $lambda**2; $c3_best = 1 + ($K3 * $lambda) + ($KC * $cro); $c_best = $dna_max / (($c1_best) * ($c3_best)); $r2_best = $c * $K1 * $lambda; $r3_best = $c * $K3 * $lambda; $r4_best = $c * $K1**2 * $lambda**2; $r5_best = $c * $K1 * $K3 * $lambda**2; $r6_best = $c * $K1**2 * $K3 * $lambda**3; $r7_best = $c * $KC * $cro; $r8_best = $c * $K1 * $KC * $lambda * $cro; $r9_best = $c * $K1**2 * $KC * $lambda**2 * $cro; # concentrations of lambda and/or cro at specific sites $lamOR1_best = $r2_best + $r4_best + $r5_best + $r6_best + $r8_bes +t + $r9_best; # eq. 6 $OR1_best = $dna_max - $lamOR1_best; $lamOR2_best = $r4 + $r6 + $r9; # eq. 6 $lamOR3_best = $r3 + $r5 + $r6; # eq. 6 $croOR3_best = $r7 + $r8 + $r9; # eq. 6 #max terms $lambda_max_best = $lambda + $lamOR1_best + $lamOR2_best + $lamOR3_ +best; # equation 1 $cro_max_best = $cro + $croOR3_best; # equation 3 # r4 term - lambda synthesis $rL1 = $K1**2 * $lambda**2; $rL2 = (1 + ($K1 * $lambda) + ($K1**2 * $lambda**2)) * (1 + ($K3 * +$lambda) + ($KC * $cro)); $rL3 = ($rL1/$rL2) * $dna_max; # next value of lambda- synthesis of more lambda - only by dna spec +ies r4 $lambda_next = ($lambda_max_best + ($ks * $rL3)) * (1 - $kdeg); # next value of cro- synthesis of more cro - only when OR1 is unbou +nd $cro_next = ($cro_max_best + ($ks * $OR1_best)) * (1 - $kdeg); } print "$lambda_next\n"; print "$cro_next\n";

In reply to making code efficient 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.