Skip to content
DeepForgeby svx
All problems
MediumCalculusca-080

Improper Integral Quadrature

Problem

Approximate the improper integral from 0 to infinity of e^(-a*x) dx by the trapezoidal rule on the truncated interval [0, t_max] with n equal subintervals.

Endpoints get weight 0.5 and interior points weight 1; multiply the weighted sum by dx = t_max / n. Assume a > 0.

Hint

The exact value is 1 / a, and the truncation error decays like e^(-a * t_max).

Test cases

case 1
in: [1,100000,50]
expected: 1.000000020833246
case 2
in: [2,100000,50]
expected: 0.5000000416666464
case 3
in: [0.5,100000,50]
expected: 2.000000010388875
case 4
in: [3,100000,50]
expected: 0.3333333958333172
Starter codePython
def improper_integral_exp(a, n, t_max):
    # Your code here
    pass

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