Skip to content
DeepForgeby svx
All problems
EasyCalculusca-232

Quadratic Form Hessian from Matrix

Problem

For the quadratic form f(x) = x^T A x with a general 2x2 matrix A, the Hessian with respect to x is the symmetric part A + A^T.

Given the entries a11, a12, a21, a22 of A, return the 2x2 Hessian as a nested list of floats. The diagonal entries are twice the diagonal of A.

Hint

Only the symmetric part of A matters because x^T A x = x^T (A + A^T) x / 2.

Test cases

case 1
in: [1,2,3,4]
expected: [[2,5],[5,8]]
case 2
in: [1,0,0,1]
expected: [[2,0],[0,2]]
case 3
in: [0,1,-1,0]
expected: [[0,0],[0,0]]
case 4
in: [2,-1,4,3]
expected: [[4,3],[3,6]]
Starter codePython
def quadratic_hessian_from_matrix(a11, a12, a21, a22):
    # Return the 2x2 Hessian
    # Your code here
    pass

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