All problems
Gradient of Determinant
Problem
Return the gradient of det(A) with respect to the 2x2 matrix A.
For A = [[a, b], [c, d]] the gradient is the cofactor matrix [[d, -c], [-b, a]].
Hint
The derivative of det(A) is the adjugate transpose, which for 2x2 is the cofactor matrix.
Test cases
case 1
in: [[[1,2],[3,4]]]
expected: [[4,-3],[-2,1]]
case 2
in: [[[2,0],[0,3]]]
expected: [[3,0],[0,2]]
case 3
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 4
in: [[[1,2],[2,4]]]
expected: [[4,-2],[-2,1]]
Starter codePython
def grad_det_2x2(A):
# Your code here
pass4 test cases · run your code against them in the editor