All problems
PLU Reconstruct Check
Problem
Verify a PLU factorization: return True if P*A equals L*U entrywise within 1e-9.
P is a permutation matrix, L is unit lower triangular, U is upper triangular, and all matrices are square and the same size.
Hint
A valid factorization satisfies P*A = L*U exactly; any mismatch means the factors are wrong.
Test cases
case 1
in: [[[1,0],[0,1]],[[1,0],[0.5,1]],[[2,1],[0,2.5]],[[2,1],[1,3]]]
expected: true
case 2
in: [[[0,1],[1,0]],[[1,0],[0,1]],[[3,4],[1,2]],[[1,2],[3,4]]]
expected: true
case 3
in: [[[1,0],[0,1]],[[1,0],[0,1]],[[1,2],[3,4]],[[1,2],[3,5]]]
expected: false
case 4
in: [[[0,1],[1,0]],[[1,0],[0,1]],[[1,2],[3,4]],[[1,2],[3,4]]]
expected: false
Starter codePython
def plu_reconstruct_check(P, L, U, A):
# Your code here
pass4 test cases · run your code against them in the editor