Skip to content
DeepForgeby svx
All problems
MediumCalculusca-326

Quadratic Plus Linear Gradient

Problem

For f(x) = x^T A x + b^T x with constant A and b, the gradient is (A + A^T) x + b.

Given A as nested rows, x, and b, return the gradient list.

Hint

Symmetrize A by adding its transpose before multiplying by x.

Test cases

case 1
in: [[[1,0],[0,1]],[1,2],[0,0]]
expected: [2,4]
case 2
in: [[[0,1],[0,0]],[3,4],[1,1]]
expected: [5,4]
case 3
in: [[[2,0],[0,3]],[1,1],[0,1]]
expected: [4,7]
Starter codePython
def quadratic_plus_linear_gradient(a, x, b):
    # Your code here
    pass

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