Skip to content
DeepForgeby svx
All problems
MediumCalculusca-033

Divergence of 2D Vector Field

Problem

For the vector field F(x, y) = [a*x^2 + b*x*y, c*x*y + d*y^2], compute its divergence at (x, y):

div F = dP/dx + dQ/dy = (2*a*x + b*y) + (c*x + 2*d*y)

Hint

The divergence of a 2D field is the trace of its Jacobian.

Test cases

case 1
in: [1,0,0,1,2,3]
expected: 10
case 2
in: [0,1,1,0,1,4]
expected: 5
case 3
in: [1,2,3,4,0,0]
expected: 0
case 4
in: [-1,1,2,-2,2,-1]
expected: 3
Starter codePython
def divergence(a, b, c, d, x, y):
    # Your code here
    pass

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