This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This is a modified version of MATLAB's rref (from Revision: 5.9.4.3 $ $Date: 2006/01/18 21:58:54) which calculates row-reduced echelon form in GF(2). Useful for linear codes. Tolerance was removed because YOLO, and because all values should only be 0 or 1. Original: https://gist.github.com/esromneb/652fed46ae328b17e104, Fork that prints more information: https://gist.github.com/nrenga/3c0ee3af2fb8ca38dcf9113376cae381 (Feb. 28, 2018) | |
% Returns the matrix M of row operations on A, i.e., Arref = M*A, and the matrix N of column operations which if applied to Arref results in a matrix of the form [I_rnk, 0; 0, 0] for the first m columns, where rnk is the gf(2) rank of A, i.e., (Arref*N)_{1:m,1:m} = (M*A*N)_{1:m,1:m} = [I_rnk, 0; 0, 0]. For a square matrix A, Arref*N = M*A*N = [I_rnk, 0; 0, 0]. | |
function [Arref, M, N, rnk] = g2rref(A) | |
[Arref, M] = gf2redref(A); | |
[Ardiag, Nt] = gf2redref(Arref'); | |
N = Nt'; | |
rnk = sum(diag(Ardiag)); |