Skip to content
DeepForgeby svx
All problems
MediumCalculusca-115

Divergence and Curl Numeric Check

Problem

Estimate the divergence and scalar curl of the 2D field F = [P(x, y), Q(x, y)] at a point with central differences (h = 1e-6).

Each component is given as a coefficient grid where coeffs[i][j] multiplies x^i * y^j; ragged rows are allowed. Return [div, curl] = [dP/dx + dQ/dy, dQ/dx - dP/dy].

Hint

Perturb one coordinate at a time for each component, then combine the four partials.

Test cases

case 1
in: [[[0,0,1],[0,0],[1,0]],[[0,0,-1],[0,0],[1,0]],1,2]
expected: [-2,-2]
case 2
in: [[[0,0],[0,1]],[[0,0],[0,1]],3,4]
expected: [7,1]
case 3
in: [[[0],[1]],[[0,1]],5,-2]
expected: [2,0]
case 4
in: [[[0,-1]],[[0],[1]],1,1]
expected: [0,2]
Starter codePython
def div_curl_numeric(p_coeffs, q_coeffs, x, y, h=1e-6):
    # Return [divergence, curl]
    # Your code here
    pass

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