All problems
Gradient of Quadratic Form
Problem
Return the gradient of the scalar function f(x) = x^T A x with respect to x:
nabla f = (A + A^T) x
For symmetric A this simplifies to 2*A*x.
Hint
The gradient of x^T A x is (A + A^T)x, since only the symmetric part contributes.
Test cases
case 1
in: [[[2,1],[0,3]],[1,1]]
expected: [5,7]
case 2
in: [[[1,0],[0,1]],[3,4]]
expected: [6,8]
case 3
in: [[[1,2],[3,4]],[1,0]]
expected: [2,5]
case 4
in: [[[0,1],[-1,0]],[1,2]]
expected: [0,0]
Starter codePython
def grad_quadratic(A, x):
# Your code here
pass4 test cases · run your code against them in the editor