Skip to content
DeepForgeby svx
All problems
HardCalculusca-087

Double Integral Polar Midpoint

Problem

Approximate a double integral in polar coordinates with the midpoint rule.

grid[i][j] holds f sampled at the midpoint of radial cell i and angular cell j, where radial midpoints are r0 + (i + 0.5)*dr. In polar coordinates dA = r dr dtheta, so the sum is multiplied by r_mid * dr * dtheta. Return 0.0 for an empty grid.

Hint

The Jacobian factor r depends on the radial cell, not on the angle.

Test cases

case 1
in: [[[1,1],[1,1]],0,1,1.5707963267948966]
expected: 6.283185307179586
case 2
in: [[[1]],0,1,6.283185307179586]
expected: 3.141592653589793
case 3
in: [[[1,1]],1,1,3.141592653589793]
expected: 9.42477796076938
case 4
in: [[[0,0],[0,0]],0,1,1]
expected: 0
case 5
in: [[[1,2],[3,4]],0,0.5,1]
expected: 3
Starter codePython
def double_polar_midpoint(grid, r0, dr, dtheta):
    # Your code here
    pass

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