All problems
Divergence Theorem Flux Numeric
Problem
Compute the outward flux of F = [a*x + d, b*y + e, c*z + f] through the surface of the unit cube [0, 1]^3 numerically.
Sample each face on a 2x2 midpoint grid and add F dotted with the outward normal times the cell area 0.25. For this linear field the midpoint rule is exact, so the result equals the divergence integral a + b + c.
Hint
The constant offsets cancel between opposite faces; only the linear coefficients survive.
Test cases
case 1
in: [1,1,1,5,6,7]
expected: 3
case 2
in: [2,-1,0.5,0,0,0]
expected: 1.5
case 3
in: [0,0,0,3,4,5]
expected: 0
case 4
in: [10,0,-2,0,0,0]
expected: 8
Starter codePython
def flux_cube_numeric(a, b, c, d, e, f):
# Your code here
pass4 test cases · run your code against them in the editor