Skip to content
DeepForgeby svx
All problems
EasyCalculusca-351

Integral of Absolute Sample Values

Problem

Given samples of |f| on a uniform grid with spacing dx, approximate the integral of |f| by the rectangle rule: dx * sum(|values|).

Return 0.0 for an empty list.

Hint

Take magnitudes before summing.

Test cases

case 1
in: [[1,-2,3],0.5]
expected: 3
case 2
in: [[-1,-1],2]
expected: 4
case 3
in: [[],1]
expected: 0
Starter codePython
def integral_abs_values(values, dx):
    # Your code here
    pass

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