3 ms·
Since y'all are code-literate, here the SymPy function for finding the CR-decomposition of any matrix A: def crd(A): """ Computes the CR decompos
by ivan_ah 6y ago
Since y'all are code-literate, here the SymPy function for finding the CR-decomposition of any matrix A:
def crd(A):
"""
Computes the CR decomposition of the matrix A.
"""
rrefA, licols = A.rref() # compute RREF(A)
C = A[:, licols] # linearly indep. cols of A
r = len(licols) # = rank(A)
R = rrefA[0:r, :] # non-zero rows in RREF(A)
return C, R
Test to check it works: https://live.sympy.org/?evaluate=A%20%3D%20Matrix(%5B%0A%20%20%5B1%2C%204%2C%205%5D%2C%0A%20%20%5B3%2C%202%2C%205%5D%2C%0A%20%20%5B2%2C%201%2C%203%5D%5D)%0A%23--%0AA%0A%23--%0Adef%20crd(A)%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20Computes%20the%20CR%20decomposition%20of%20the%20matrix%20A.%0A%20%20%20%20%22%22%22%0A%20%20%20%20rrefA%2C%20licols%20%3D%20A.rref()%20%20%23%20compute%20RREF(A)%0A%20%20%20%20C%20%3D%20A%5B%3A%2C%20licols%5D%20%20%20%20%20%20%20%20%20%20%23%20linearly%20indep.%20cols%20of%20A%0A%20%20%20%20r%20%3D%20len(licols)%20%20%20%20%20%20%20%20%20%20%20%23%20%3D%20rank(A)%0A%20%20%20%20R%20%3D%20rrefA%5B0%3Ar%2C%20%3A%5D%20%20%20%20%20%20%20%20%20%23%20non-zero%20rows%20in%20RREF(A)%0A%20%20%20%20return%20C%2C%20R%0A%23--%0AC%2C%20R%20%3D%20crd(A)%0A%23--%0AC%0A%23--%0AR%0A%23--%0AC*R%0A%23--%0A https://live.sympy.org/?evaluate=A%20%3D%20Matrix(%5B%0A%20%...