<a href="https://colab.research.google.com/github/tofighi/Linear-Algebra/blob/main/RREF_Gaussian_Elimination.ipynb" target="_parent"></a>

# RREF Calculation
Using the `SymPy` library (Symbolic Python), we can obtain the exact unique RREF of any matrix easily. With the help of `sympy.Matrix().rref()` method, we can put a matrix into Reduced Row Echelon Form. `Matrix().rref()` returns a tuple of two elements. The first is the Reduced Row Echelon Form (RREF), and the second is a tuple of indices of the pivot columns (columns with leading 1s).


```python
import sympy as sp
from sympy import Matrix, linsolve, symbols
sp.init_printing(use_unicode=True)
```

#Example

Solve the following system of linear equations:

$
\left\{\begin{aligned} 
x+3y+5z &=8 \\
-2x+4y+9z &=3 \\
-x+7y+14z &=11 \end{aligned}\right.
$


```python
A = sp.Matrix([[1,3,5,8],[-2,4,9,3],[-1,7,14,11]])
A
```




$\displaystyle \left[\begin{matrix}1 & 3 & 5 & 8\\-2 & 4 & 9 & 3\\-1 & 7 & 14 & 11\end{matrix}\right]$




```python
#get the exact RREF of A with the pivot columns identified
B = A.rref()
B 
```




$\displaystyle \left( \left[\begin{matrix}1 & 0 & - \frac{7}{10} & \frac{23}{10}\\0 & 1 & \frac{19}{10} & \frac{19}{10}\\0 & 0 & 0 & 0\end{matrix}\right], \  \left( 0, \  1\right)\right)$




```python
# reduced matrix only
B[0]
```




$\displaystyle \left[\begin{matrix}1 & 0 & - \frac{7}{10} & \frac{23}{10}\\0 & 1 & \frac{19}{10} & \frac{19}{10}\\0 & 0 & 0 & 0\end{matrix}\right]$




```python
# pivot columns only
B[1]
```

02ce056e6c7db2b840d30dff2f54ac5b87b1c578
ipynb
Jupyter Notebook
RREF_Gaussian_Elimination.ipynb
tofighi/Linear-Algebra
bea7d2a4a81e0c49b324f23c47cf03db72e376cf
CC0-1.0
RREF_Gaussian_Elimination.ipynb
tofighi/Linear-Algebra
bea7d2a4a81e0c49b324f23c47cf03db72e376cf
CC0-1.0
RREF_Gaussian_Elimination.ipynb
tofighi/Linear-Algebra
bea7d2a4a81e0c49b324f23c47cf03db72e376cf
CC0-1.0
Qwen/Qwen-72B
1. YES
2. YES