All problems
Trace-Inverse Gradient
Problem
For L(A) = trace(C A^{-1}) with constant matrix C, the gradient with respect to A is -(A^{-1} C A^{-1})^T.
Given the entries of the 2x2 matrix A as a, b, c, d and the entries of C as p, q, r, s, return the 2x2 gradient as a nested list. Return None when det(A) == 0.
Hint
Differentiate A A^{-1} = I to get d(A^{-1}) = -A^{-1} dA A^{-1}, then read off the gradient.
Test cases
case 1
in: [1,0,0,1,1,2,3,4]
expected: [[-1,-3],[-2,-4]]
case 2
in: [2,0,0,1,1,0,0,1]
expected: [[-0.25,0],[0,-1]]
case 3
in: [1,2,3,4,1,0,0,1]
expected: [[-5.5,3.75],[2.5,-1.75]]
case 4
in: [1,2,3,6,1,0,0,1]
expected: null
Starter codePython
def trace_inverse_gradient(a, b, c, d, p, q, r, s):
# Return the 2x2 gradient
# Your code here
pass4 test cases · run your code against them in the editor