简体   繁体   中英

Want to find the row operations when inverting a matrix

I have a sequence of matrices and I want to find the inverse of each one. I suspect that there is a pattern to the row operations when putting it into reduced echelon form/inverting. Is there a library in python that I can use to give me a sequence of row operations such as R1 = R1-aR2, R3=R1+bR4, etc etc until it is in reduced row echelon form or completely inverted.

I tried googling but it's mostly guides on how to invert a matrix.

There are libraries in Python that can help you find the sequence of row operations when inverting a matrix. One such library is SymPy, which is a Python library for symbolic mathematics. It has a built-in function called rref (reduced row echelon form) that can be used to put a matrix in reduced row echelon form, and a inv function that can be used to find the inverse of a matrix.

Here is an example of how you can use SymPy to find the row operations needed to invert a matrix:

from sympy import *

# Define the matrix
A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])

# Find the reduced row echelon form of the matrix
rref, pivots = A.rref()

# Find the inverse of the matrix
A_inv = A.inv()

# Print the row operations
for i in range(len(pivots)):
    row = pivots[i]
    print(f"R{row+1} = R{row+1} - {rref[i, row]}*R{i+1}")

This will print the sequence of row operations needed to find the inverse of matrix A.

You can also use SymPy's rref() function to get both the row-echelon form and the pivot columns of the matrix in one call.

It's also worth noting that using libraries like numpy and scipy have inverse function which you can use to get the inverse of a matrix without doing the operations manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM