Skip to content
DeepForgeby svx
All problems
MediumCalculusca-165

Taylor Expansion 2D Quadratic

Problem

Evaluate the general quadratic f(x, y) = c0 + cx*x + cy*y + 0.5*cxx*x^2 + cxy*x*y + 0.5*cyy*y^2 at (x0 + dx, y0 + dy) using its second-order Taylor expansion about (x0, y0).

Because f is quadratic the expansion is exact: f + fx*dx + fy*dy + 0.5*(fxx*dx^2 + 2*fxy*dx*dy + fyy*dy^2). Return the value.

Hint

Collect the value, the gradient term, and the Hessian term at the expansion point.

Test cases

case 1
in: [0,0,0,2,0,0,1,0,0.1,0]
expected: 1.21
case 2
in: [0,0,0,0,1,0,2,3,0.5,-0.5]
expected: 6.25
case 3
in: [5,0,0,0,0,0,1,1,2,3]
expected: 5
case 4
in: [1,2,3,0.5,1,2,1,1,0.5,0.5]
expected: 13.5625
Starter codePython
def taylor2d_quadratic(c0, cx, cy, cxx, cxy, cyy, x0, y0, dx, dy):
    # Your code here
    pass

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