improper integral trapezoid and simpson rule

1.1k Views Asked by At

I have to use both trapezoid and Simpson's rule to find $\int_0^\infty e^{-x}dx$ starting with $h=2$ where $h$ is the length of subintervals $[x_i,x_{i+1}]$.

1

There are 1 best solutions below

0
On BEST ANSWER

A well-known trick is to make the change of variables

$$ x = \frac{t}{1 - t} $$

So that the integral becomes

$$ \int_0^{+\infty} e^{-x}{\rm d}x = \int_0^1 \frac{e^{-t/(1-t)}}{(1 -t)^2}{\rm d}t $$

the trick here is that this argument goes to zero when $t\to 1$, so you can manually set the last point in your quadrature to $0$, here's an example in python

import numpy as np

def f(t):

    return np.exp(-t/(1- t)) / (1 - t)**2

h = 0.01
x = np.arange(0, 1, h)

S = 0.5 * h * (f(0) + 2 * f(x[1 : ]).sum() + 0)

print S