For all mathematicians... This code solves $var_no number of equations for $var_no number of variables. It uses Crout's Reduction Algorithm. The 2D array called @matrix is the coefficient matrix.
# Crout's Reduction Algorithm if($messages eq "on"){ print "$n<code>$n"; } $beginning_time = localtime(time); if($matrix[1][1]!=0){ for($k=2;$k<=$var_no;$k+=1){ for($i=$k;$i<=$var_no;$i+=1){ for($j=($var_no+1);$j>=($k-1);$j-=1){ if($messages eq "on"){ print $matrix[$i][$j]; print " ---> "; } # Crout's Reduction Formula $matrix[$i][$j] -= $matrix[$k-1][$j] * ( $matrix[$ +i][$k-1] / $matrix[$k-1][$k-1] ); if($messages eq "on"){ print $matrix[$i][$j]; print $n; } } } } } if($messages eq "on"){ for($i=1;$i<=($var_no+1);$i+=1){ for($j=1;$j<=($var_no+1);$j+=1){ print $matrix[$i][$j]; print "&nbsp;&nbsp;&nbsp;"; } print $n } print "&lt;/code&gt;$n"; } # Solving the equations once the matrix is reduced. for($i=$var_no;$i>=1;$i-=1){ $sum = 0; for($k=($i+1);$k<=$var_no;$k+=1){ $sum += $x[$k] * $matrix[$i][$k]; } $x[$i] = ( $matrix[$i][$var_no+1] - $sum) / $matrix[$i][$i] } $ending_time = localtime(time); if($messages eq "on"){ print "$n<code>\n"; for($i=1;$i<=$var_no;$i+=1){ print $x[$i]; print $n } print "$nThe whole thing done in only ".($ending_time-$beginni +ng_time)." seconds."; print "&lt;/code&gt;$n"; }

In reply to Crout's Reduction for Matrices by sinan

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.