Skip to content
DeepForgeby svx
All problems
MediumCalculusca-321

Log-Determinant Gradient 2x2

Problem

For f(A) = log det(A) with a nonsingular 2x2 matrix A = [[a, b], [c, d]], the gradient is A^{-T} = [[d, -c], [-b, a]] / det(A).

Given the entries, return the gradient matrix.

Hint

Differentiate log det(A) to get the transpose of the inverse.

Test cases

case 1
in: [1,0,0,1]
expected: [[1,0],[0,1]]
case 2
in: [2,1,0,1]
expected: [[0.5,0],[-0.5,1]]
case 3
in: [1,2,3,5]
expected: [[-5,3],[2,-1]]
Starter codePython
def logdet_gradient_2x2(a, b, c, d):
    # Your code here
    pass

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