Can I use Trapezoidal rule to calculate an improper integral?

For example, \int_{a}^{infinity} e^{-x} dx is an improper integral which can be calculated exactly as e^{-a}.

Can we solve this integral by multiple segment Trapezoidal rule when we already know that the upper limit is infinity?

Yes, we can solve it in spite of the upper limit being infinity. We first need to make a change of variables such as t=\frac{1}{x}, then dx=-\frac{1}{t^2}dt giving \int_{1/a}^{0} e^{-1/t} (-1/t^2) dt

But even for this integral we have issues as the integrand gives division by zero problems at t=0 (although the limit itself is zero at t=0).

The MATLAB program that can be downloaded at (better to download it as the single quotes do not translate well with matlab editor) shows that we get accurate results for transformed integral with 256 segments.
% Simulation : Can I use Trapezoidal rule for an improper integral?
% Language : Matlab 2007a
% Authors : Autar Kaw,
% mfile available at
% Last Revised : July 15, 2008
% Abstract: This program shows use of multiple segment Trapezoidal
% rule to integrate exp(-x) from x=a to infinity, where a>0.
clear all
disp(‘This program shows the convergence of getting the value of ‘)
disp(‘an improper integral using multiple segment Trapezoidal rule’)
disp(‘Author: Autar K Kaw.’)

%INPUTS. If you want to experiment, these are the only variables
% you should and can change.
% a = Lower limit of integration

fprintf(‘\nFinding the integral of exp(-x) from a to infinity where a=%g’,a)

syms x
% integrand exp(-x)
fprintf(‘\n\nExact value of integral = %f’,valexact)
disp( ‘ ‘)

% Transformed integrand by change of variables
% Limits of integration

%finding value of the integral using 16, 32, 64, 128 and 256 segments
for k=4:1:8
for i=1:1:n-1
% See how f(b) is not added as f(b)=infinity. But
% using a different value of the function at one point or
% finite number of points does not change the value of the
% integral. We are substituting f(b)=0
fprintf(‘\nApproximate value of integral =%f with %g segments’,sum,n)
disp(‘ ‘)
This program shows the convergence of getting the value of
an improper integral using multiple segment Trapezoidal rule
Author: Autar K Kaw.

Finding the integral of exp(-x) from a to infinity where a=0.5

Exact value of integral = 0.606531

Approximate value of integral =0.605971 with 16 segments
Approximate value of integral =0.606496 with 32 segments
Approximate value of integral =0.606521 with 64 segments
Approximate value of integral =0.606528 with 128 segments
Approximate value of integral =0.606530 with 256 segments

Published with MATLAB® 7.3

Now someone may rightly point out that it works well because the limit of the integrand is zero at the lower limit of integration for the above mentioned integral.

So go ahead, modify the program for doing this improper integral \int_{0}^{4} \frac{1}{\sqrt {x}} dx and see how well it works. In this case the integrand is singular at x=0 and one would have to assume the function to be a number other than infinity at x=0 for applying the multiple segment Trapezoidal rule.

How many segments do you need to get an accurate answer for this integral?


This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at

Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.


Author: Autar Kaw

Autar Kaw ( is a Professor of Mechanical Engineering at the University of South Florida. He has been at USF since 1987, the same year in which he received his Ph. D. in Engineering Mechanics from Clemson University. He is a recipient of the 2012 U.S. Professor of the Year Award. With major funding from NSF, he is the principal and managing contributor in developing the multiple award-winning online open courseware for an undergraduate course in Numerical Methods. The OpenCourseWare ( annually receives 1,000,000+ page views, 1,000,000+ views of the YouTube audiovisual lectures, and 150,000+ page views at the NumericalMethodsGuy blog. His current research interests include engineering education research methods, adaptive learning, open courseware, massive open online courses, flipped classrooms, and learning strategies. He has written four textbooks and 80 refereed technical papers, and his opinion editorials have appeared in the St. Petersburg Times and Tampa Tribune.

3 thoughts on “Can I use Trapezoidal rule to calculate an improper integral?”

  1. Of course the calculation of improper integral of a function becomes more easy after using an appropriate change variable. Hence we can calculate it by simple integration scheme such as trapedzoidal rule or both of simpson 1/3 and 2/3 rules. But, suppose INT[exp(-x)dx] is still calculated with lower and upper limit of integrations 0 and infinity respectively, I am sure we need Laguerre-Gauss quadrature’s scheme that it’s accuracy depends on the order of Laguerre polynomial. The next question, what’s Gauss quadrature’s scheme that suitable for calculating the above improper integral if the lower and upper limits of integration are a and infinity respectively.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: