# improper integral trapezoid and simpson rule

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}]$.

• With these limit so it cannot be done. How can you split infinity into strips of width 2? Is it necessary considering the function has an elementary function – Henry Lee May 23 '18 at 15:04
• Exactly what I was thinking. Should I just integrate it in a usual way? @HenryLee – mandella May 23 '18 at 15:06

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