Skip to content
DeepForgeby svx
All problems
EasyCalculusca-368

Trapezoid on Exponential Samples

Problem

Sample f(x) = exp(x) at n + 1 equally spaced points on [a, b] and integrate with the trapezoidal rule.

Given a, b, and n, return the estimate. Return 0.0 when n < 1.

Hint

Build the sample heights analytically instead of a list first.

Test cases

case 1
in: [0,1,10]
expected: 1.7197134913893146
case 2
in: [0,2,4]
expected: 6.521610109481282
case 3
in: [-1,1,100]
expected: 2.3504807335115396
Starter codePython
def trapezoid_on_exponential_samples(a, b, n):
    # Your code here
    pass

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