Gauss-Jordan matrix inversion: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way)
m (→‎version 2: changed whitespace, added a comment.)
Line 3,279:
{{trans|PL/I}}
<lang rexx>/*REXX program performs a (square) matrix inversion using the Gauss─Jordan method. */
data= ' 8 3 7 5 9 12 10 11 6 2 4 13 14 15 16 17' /*the matrix element values. */
call build 4 /*assign data elements to the matrix. */
call show '@', 'The matrix of order ' n " is:" /*display the (square) matrix. */
Line 3,285:
call invert /*invert the matrix, store result in X.*/
call show 'X', "The inverted matrix is:" /*display (inverted) auxiliary matrix. */
exit 0 /*stick a fork in it, we're all done. */
exit 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
aux: x.= 0; do i=1 for n; x.i.i= 1; end; return
Line 3,293:
@.r.c= word(data, #); w= max(w, length(@.r.c) )
end /*c*/ /*W: max width of a number*/
end /*r*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
invert: do k=1 for n; t= @.k.k /*divide each matrix row by T. */
Line 3,305:
end /*c*/
end /*r*/
end /*k*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: parse arg ?, title; say; say title; f= 4 /*F: fractional digits precision.*/
Line 3,312:
else _= _ right(format(x.r.c, w, f), w + f + length(.))
end /*c*/; say _
end /*r*/; return</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
Line 3,327:
-0.1064 -0.0855 0.0883 0.0779
</pre>
 
=={{header|Rust}}==
<lang rust>