%% Reduced Row Echelon Form of Matrix
% Create a matrix and calculate the reduced row echelon form. In this form, the matrix has leading 1s in the pivot position of each column.

A = magic(3)

%

RA = rref(A)

% The 3-by-3 magic square matrix is full rank, so the reduced row echelon form is an identity matrix.
%
% Now, calculate the reduced row echelon form of the 4-by-4 magic square matrix. Specify two outputs to return the nonzero pivot columns. Since this matrix is rank deficient, the result is not an identity matrix.

B = magic(4)

%

[RB,p] = rref(B)

% Copyright 2018 The MathWorks, Inc.