Reduced row echelon form: Difference between revisions

Content deleted Content added
Shuisman (talk | contribs)
No edit summary
added Ursala
Line 675: Line 675:
-0.0 1.0 0.0 1.0
-0.0 1.0 0.0 1.0
-0.0 -0.0 1.0 -2.0 </pre>
-0.0 -0.0 1.0 -2.0 </pre>

=={{header|Ursala}}==
The most convenient representation for a matrix in Ursala is as a list of lists.
Several auxiliary functions are defined to make this task more manageable.
The pivot function reorders the rows to position the first column entry with maximum
magnitude in the first row.
The descending function is a second order function abstracting the pattern
of recursion down the major diagonal of a matrix. The reflect function allows
the code for the first phase in the reduction to be reused during the upward
traversal by appropriately permuting the rows and columns. The row_reduce function
adds a multiple of the top row to each subsequent row so as to cancel the
first column. These are all combined in the main rref function.

<lang Ursala>#import std
#import flo

pivot = -<x fleq+ abs~~bh
descending = ~&a^&+ ^|ahPathS2fattS2RpC/~&
reflect = ~&lxPrTSx+ *iiD ~&l-~brS+ zipp0
row_reduce = ^C/vid*hhiD *htD minus^*p/~&r times^*D/vid@bh ~&l
rref = reflect+ (descending row_reduce)+ reflect+ descending row_reduce+ pivot

#show+

test =

printf/*=*'%8.4f' rref <
<1.,2.,-1.,-4.>,
<2.,3.,-1.,-11.>,
<-2.,0.,-3.,22.>></lang>
output:
<pre>
1.0000 0.0000 0.0000 -8.0000
0.0000 1.0000 0.0000 1.0000
0.0000 0.0000 1.0000 -2.0000</pre>
It should be noted that in practice, this
task could be accomplished more easily and efficiently by
invoking the msolve library function, which interfaces with the lapack library if
available.