All problems
Divergence in Three Dimensions
Problem
For the vector field F(x, y, z) = [a*x^2*y, b*y^2*z, c*z^2*x], the divergence is 2*a*x*y + 2*b*y*z + 2*c*z*x.
Given the coefficients a, b, c and the point (x, y, z), return the divergence value.
Hint
Differentiate each component with respect to its own coordinate, then sum.
Test cases
case 1
in: [1,1,1,1,1,1]
expected: 6
case 2
in: [1,0,0,2,3,4]
expected: 12
case 3
in: [2,3,4,0,0,0]
expected: 0
case 4
in: [1,1,0,1,2,3]
expected: 16
Starter codePython
def divergence_3d(a, b, c, x, y, z):
# Your code here
pass4 test cases · run your code against them in the editor