Skip to content
DeepForgeby svx
All problems
MediumCalculusca-161

Curl of Gradient Identity Check

Problem

The identity curl(grad f) = 0 holds for any smooth scalar field f. Verify it numerically for f = a*x^2*y + b*y^2*z + c*z^2*x.

Compute the gradient and then its curl with central differences (step h = 1e-5) and return the Euclidean norm of the resulting vector, which should be near 0.0.

Hint

Gradients are curl-free; the mixed partials cancel pairwise.

Test cases

case 1
in: [1,1,1,1,2,3]
expected: 0
case 2
in: [2,-1,0.5,0.5,-1,2]
expected: 0
case 3
in: [0,3,2,2,2,2]
expected: 0
case 4
in: [-2,1,-1,1,1,1]
expected: 0
Starter codePython
def curl_of_gradient_check(a, b, c, x, y, z, h=1e-5):
    # Your code here
    pass

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