Skip to content
DeepForgeby svx
All problems
MediumCalculusca-236

Log-Determinant Gradient

Problem

For a 2x2 matrix A, the gradient of log(det(A)) with respect to the entries is the inverse transpose A^{-T}.

Given the entries a, b, c, d of A, return this 2x2 gradient as a nested list of floats. Return None when det(A) == 0.

Hint

Log-determinant is a standard barrier function; its gradient is the inverse transpose.

Test cases

case 1
in: [1,2,3,4]
expected: [[-2,1.5],[1,-0.5]]
case 2
in: [2,0,0,4]
expected: [[0.5,0],[0,0.25]]
case 3
in: [1,0,0,1]
expected: [[1,0],[0,1]]
case 4
in: [1,2,2,4]
expected: null
Starter codePython
def log_det_gradient(a, b, c, d):
    # Return the 2x2 gradient of log(det(A))
    # Your code here
    pass

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