Skip to content
DeepForgeby svx
All problems
EasyCalculusca-052

Hessian Trace

Problem

Return the trace of the Hessian (the Laplacian) of the 3D quadratic f(x, y, z) = a*x^2 + b*y^2 + c*z^2 + d*x*y + e*y*z + f*z*x.

The mixed terms do not contribute to the diagonal, so the trace is 2*a + 2*b + 2*c. The inputs d, e, f are accepted to show that they are irrelevant here.

Hint

The trace sums H_xx + H_yy + H_zz, and each pure second derivative is twice its coefficient.

Test cases

case 1
in: [1,2,3,0,0,0]
expected: 12
case 2
in: [1,1,1,5,-2,7]
expected: 6
case 3
in: [0,0,0,1,1,1]
expected: 0
case 4
in: [-1,2,0,0,0,0]
expected: 2
case 5
in: [2.5,-0.5,1,0,0,0]
expected: 6
Starter codePython
def hessian_trace(a, b, c, d, e, f):
    # Your code here
    pass

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