All problems
Double Integral Midpoint Rule
Problem
Approximate a double integral over a rectangle with the 2D midpoint rule.
grid[j][i] holds f sampled at the midpoint of cell (i, j), with uniform cell sizes dx and dy. Return the sum of all grid values times dx * dy.
Hint
Sum every cell value, then multiply once by the cell area dx * dy.
Test cases
case 1
in: [[[1,1],[1,1]],0.5,0.5]
expected: 1
case 2
in: [[[1,2],[3,4]],1,1]
expected: 10
case 3
in: [[[0.5,1.5],[2.5,3.5]],2,0.5]
expected: 8
case 4
in: [[],1,1]
expected: 0
case 5
in: [[[],[]],1,1]
expected: 0
Starter codePython
def double_midpoint(grid, dx, dy):
# Your code here
pass5 test cases · run your code against them in the editor