All problems
Riemann Sums Left and Right
Problem
Given sampled function values on a uniform grid with spacing dx, return both the left and right Riemann sums as a list [left, right].
left = dx * sum(values[0:-1]) and right = dx * sum(values[1:]).
If fewer than two samples are supplied, both sums are 0.0.
Hint
The left sum drops the final sample; the right sum drops the first sample.
Test cases
case 1
in: [[1,1,1,1],0.5]
expected: [1.5,1.5]
case 2
in: [[0,1,4,9],1]
expected: [5,14]
case 3
in: [[2,4,8],0.25]
expected: [1.5,3]
case 4
in: [[3],1]
expected: [0,0]
Starter codePython
def riemann_sums(values, dx):
# Return [left_sum, right_sum]
# Your code here
pass4 test cases · run your code against them in the editor