Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-240

M-matrix Inverse Positivity Check

Problem

Return True if the 2x2 matrix A is invertible and every entry of its inverse is non-negative (at least -1e-9).

Such matrices are M-matrices, and their inverses are entrywise non-negative under the usual sign conditions.

Hint

M-matrices have positive diagonal, non-positive off-diagonal, and non-negative inverses.

Test cases

case 1
in: [[[2,-1],[-1,2]]]
expected: true
case 2
in: [[[1,2],[3,4]]]
expected: false
case 3
in: [[[4,-1],[-1,3]]]
expected: true
case 4
in: [[[1,1],[1,1]]]
expected: false
Starter codePython
def is_inverse_nonnegative_2x2(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor