C Base Reduce Row Echelon Code

I recently needed some code to compute the reduced row echelon of a matrix. Applications such as Matlab, Mathematics, sympy and R support this functionality out of the box. Libraries such as LAPACK do not, including the linear algebra package in Python. The linear algebra package in Python has some surprising omissions which appear to be by design.

Here I include a C based function that will compute the reduced row echelon. It uses partial pivoting to prevent numerical stability but I don’t know how it would fare when confronted with a large matrix (i.e > 500 rows or columns).

It uses a simple matrix type called TMATRIX. It shouldn’t be difficult to modify code if you use a different matrix structure.

To call rref use:

The 1e-9 argument is the setting that decides whether a value is zero or not. Numbers below tolerance are considered zeros.

The output matrix givne the input should be:

This entry was posted in Modeling, Pathways, Programming, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published.