All problems
Gradient of the Determinant (Matrix Calculus)
Problem
For the 2x2 matrix A = [[a, b], [c, d]], the gradient of the determinant with respect to the entries is the cofactor matrix.
Since det(A) = a*d - b*c, return [[d, -c], [-b, a]] as a nested list of floats.
Hint
Each partial derivative is the cofactor of the corresponding entry.
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,1,1,1]
expected: [[1,-1],[-1,1]]
case 4
in: [0,0,0,0]
expected: [[0,0],[0,0]]
Starter codePython
def gradient_det(a, b, c, d):
# Return the 2x2 gradient of det(A)
# Your code here
pass4 test cases · run your code against them in the editor