Skip to content
DeepForgeby svx
All problems
EasyCalculusca-296

Cumulative Trapezoid Integration

Problem

Given function values on a uniform grid with spacing dx, return the running trapezoidal integral after each interval: F_k = F_{k-1} + 0.5 * (v[k-1] + v[k]) * dx for k = 1..n-1.

Return a list of n-1 prefix integrals; return [] when fewer than two samples are given.

Hint

Accumulate each trapezoid contribution into a running total.

Test cases

case 1
in: [[1,1,1,1],0.5]
expected: [0.5,1,1.5]
case 2
in: [[0,1,2,3],1]
expected: [0.5,2,4.5]
case 3
in: [[2,4],0.25]
expected: [0.75]
Starter codePython
def cumulative_trapezoid_integral(values, dx):
    # Your code here
    pass

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