Python sympy Matrix.rref() Method

Introduction:

In this tutorial, we are learning about the Matrix.rref() method in Python sympy. The full form of rref is the Reduced Row-Echelon Form library. The matrix's row echelon means that Gaussian elimination is done in rows, and the column echelon means that Gaussian elimination is done in every column. We can easily reduce the matrix to row echelon form with the help of the sympy.Matrix().rref() method. The Matrix().rref() returns a tuple of two elements. The first element is a reduced row echelon form, and the second element is a tuple of pivot column indices.

Syntax:

The syntax of the Matrix.rref() method in Python sympy is given below -

Return value:

The return value of the Matrix.rref() method in Python sympy is given below -

The Matrix.rref() method returns a tuple with a first element of type Matrix and a second element of type Tuple.

Program code:

Here, we give the program code of the Matrix.rref() method in Python sympy. The code is given below -

Output:

Now, we run the above code and find the matrix of the echelon row and the pivot columns. The output is given below -

Matrix : Matrix([[1, 2, 1, 2, 4, 1], [2, 0, 4, 7, 2, 1], [-1, -2, -1, -3, -1, -4]]) 
The matrix of the echelon row and the pivot columns are: (Matrix([
[1, 0,    2, 0, 23/2, -10],
[0, 1, -1/2, 0, -3/4, 5/2],
[0, 0,    0, 1,   -3,   3]]), (0, 1, 3))

Program code:

Here we give another program code of the Matrix.rref() method in Python sympy. The code is given below -

Output:

Now, we run the above code and find the matrix of the echelon row and the pivot columns. The output is given below -

Matrix : Matrix([[17, 0, 81, 45], [87, 26, 7, 10], [-10, -14, -70, -20]]) 
The matrix of the echelon row and the pivot columns are: (Matrix([
[1, 0, 0,   7785/17812],
[0, 1, 0, -32135/26718],
[0, 0, 1,  24785/53436]]), (0, 1, 2))

Conclusion:

In this tutorial, we are learning about the Matrix.rref() method in Python sympy. Here we learn the syntax and return value of the Matrix.rref() method. We also learn some program code by using this method in Python.