Improper Integrals: Ü Two Ways To Classify
Improper Integrals: Ü Two Ways To Classify
nb 1
Improper Integrals
Whenever we write Ÿa f (x) „ x we assume that f HxL is continuous on the open interval Ha, bL. The integral is improper if a
b
or b is infinite or if f is undefined at a or b.
One classification is finite or infinite domain, depending on whether a and b are both finite or at least one is infinite. The
è!!! ƒƒ 1
ƒƒ
‡ ÅÅÅÅÅÅÅÅ
è!!!ÅÅÅÅÅ „ x = 2 x ƒƒ = 2
ƒƒ 0
1
1
0 x
-1 ƒƒƒ ¶
‡ ÅÅÅÅ2ÅÅ „ t = ÅÅÅÅÅÅÅÅÅÅ ƒƒƒƒ
¶
t ƒ 1
1
= 1
1 t
‡
¶
sin x
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅ „ x
0 x
‡ ÅÅÅÅÅ
1
1
„x
0 x
and
‡
¶
1
ÅÅÅÅÅ „ x
1 x
ü Why Trapezoidal and Simpson's methods cannot be used for improper integrals
The trapezoidal and Simpson's methods use the value of the integrand at the endpoints of the domain of integration. If the
function is not defined there, these methods cannot be used. The midpoint and Gauss-Legendre methods use only interior
points, so these are better suited to improper integrals. However, as we will see, that these methods always return a result is
not necessarily a good thing. Interior point methods return finite values when applied to both convergent and divergent
integrals. It is something of an art to decide when an integral is divergent or how accurately the numerical value returned
matches the integral.
improper_integrals.nb 2
Improper integrals present great challenges for numerical integration, but they are important in certain parts of science like
physics. Oscillatory integrals are generally much harder than non-oscillatory integrals, and we will not consider them until
the end of this section.
There is one kind of proper integral which also causes problems for numerical integration, one in which the first or higher
derivative of the integrand is undefined at an endpoint. Numerical integration methods depend on functions being "like"
polynomials, and functions with undefined derivatives are not like polynomials.
1 è!!!
Let's look at an example: Ÿ0 x „ x. This is a proper integral, but the first derivative of the integrand vanishes at 0. We can
integrate exactly using the Fundamental Theorem of Calculus:
è!!! 2 3 ƒƒƒ 1
‡ x „ x = ÅÅÅÅÅ x ÅÅ2ÅÅ ƒƒƒƒ
ƒ0
1
2
= ÅÅÅÅÅ
0 3 3
Let's try numerical methods on this integral, starting with the midpoint method with 20 subdivisions. We start by defining
the midpoint method:
SumAf@xD, 9x, a + =E
b−a b−a b−a
In[90]:= midpoint@f_, a_, b_, n_D := , b,
n 2n n
Out[92]= 0.667295
Not a great answer. Let's try Gauss-Legendre integration with 20 subdivisions. Remember the Gauss-Legendre integrator
from previous notes:
j
jfA z
z,
b−a a+b b−a
2 k {
SumAgc@@i, 2DD − gc@@i, 1DDE + fA +
8i, 1, Length@gcD<E
2 2 2 2
http://www.math.ntnu.no/num/nnm/Program/Numlibc/gauss_co.c
improper_integrals.nb 3
Out[95]= 0.666679
As usual, the Gauss-Legendre method produces a better result than the midpoint method but not as good as we might
expect from past experience. As always, to know how accurate your result is you should calculate it several ways and only
trust the answers that agree with each other.
Improper integrals are even more difficult for numerical methods. For a start, you can't even approximate an improper
integral with infinite domain, because you can't know at what points to evaluate the function. Any time you encounter an
integral with infinte domain, you must use a change of variable to change it to one with finite domain before applying
numerical methods. Here's an example:
ƒƒ ¶
ƒ
‡ e-x „ x = -e-x ƒƒƒƒ
¶
ƒ 0
= 1
0
First we break the integral into two parts, a proper integral and an improper integral with infinite domain:
‡ e-x „ x = ‡ e-x „ x + ‡
¶ 1 ¶
e-x „ x
0 0 1
-1
Next we change the improper part to an integral on a finite domain, using the transform x = ÅÅÅÅ1t , dx = ÅÅÅÅ
ÅÅÅÅ dt:
t2
‡ e-x „ x = ‡ ÅÅÅÅÅÅÅÅ
-1
¶ 1 ÅÅÅÅtÅÅÅ
e
ÅÅÅÅ „ t
1 0 t2
Note that the resulting integral is proper, since the integrand does not go to infinity at either end of the domain of
integration.
improper_integrals.nb 4
, 8t, 0, 1<E
−1
E t
In[96]:= PlotA
t2
0.5
0.4
0.3
0.2
0.1
Out[96]= Graphics
Let's calculate Ÿ0 e-x „ x using the 20-point Gauss-Legendre approximation on both parts.
¶
Out[99]//InputForm=
1.00000015715476
Let's try the 20-point and 40-point Gauss-Legendre method on two improper integrals, which which is convergent and one
which is not.
A = ‡ ÅÅÅÅÅÅÅÅ
è!!!ÅÅÅÅÅ „ x
1
1
0 x
B = ‡ ÅÅÅÅÅ „ x
1
1
0 x
improper_integrals.nb 5
f@t_D := è!!!!
1
t
1
g@t_D :=
t
A20 = gaussLegendre@f, 0, 1, gc20D
A40 = gaussLegendre@f, 0, 1, gc40D
B20 = gaussLegendre@g, 0, 1, gc20D
B40 = gaussLegendre@g, 0, 1, gc40D
Out[103]=
1.95753
Out[104]=
1.9785
Out[105]=
7.19548
Out[106]=
8.55709
Thinking intuitively, you can see that the two estimates for Ÿ0 ÅÅÅÅ
è!!!
ÅÅÅÅ!ÅÅ „ x are fairly close together; you could expect that the
11
integral converges to a value not too different from the computed values. On the other hand the two estimates for Ÿ0 ÅÅÅÅ1x „ x
x
1
are very different, leading to the suspicion that maybe the integral does not converge at all.
We could get a better value for a convergent improper integral by using more and more points with the Gauss-Legendre
method, but that is wasteful. Generally speaking, an improper integral is easy to calculate away from its singularity or bad
point. For example:
è!!! ƒƒƒƒ 1
‡ è!!!ÅÅÅÅÅ „ x = 2 x ƒƒƒƒ 0.1 = 1.36754
1
1
ÅÅÅÅÅÅÅÅ
0.1 x
yields readily to the 20-point Gauss-Legendre method. The 20-point Gauss-Legendre approximation for this integral is:
improper_integrals.nb 6
In[107]:=
gaussLegendre@f, 0.1, 1, gc20D
Out[107]=
1.36754
We want to use lots of points to approximate the integral near its singularity but not so many elsewhere. Here's an idea: do
three approximations:
Rº ‡ f HxL „ x
b
Sº‡ f HxL „ x
a+b
ÅÅÅÅ
2ÅÅÅÅÅÅ
T º ‡ f HxL „ x
b
a+b
ÅÅÅÅ2ÅÅÅÅÅÅ
We expect R º S + T, and if the equation holds with reasonable accuracy then we can accept S + T as the correct integral.
(In general R, S and T will have been calculated with the same method and number of points, so the sum S + T is calculated
with twice as many points as R and therefore is probably more accurate.) If the two values are not close enough together,
we try to calculate S and T separately, using the same divide-and-conquer method. This is called the adaptive method of
numerical integration. It puts more effort into those parts of the domain where the integral is hard to calculate. The best way
to express the algorithm is through recursion. Note the parameter "remainingIterations" that prevents infinite recursive calls.
First we give the algorithm is pseudo-code. We assume the existence of a method of approximating integrals called numeri-
calIntegral(f,a,b) that uses only interior points. This might be a midpoint or Romberg or Gauss-Legendre method with a
fixed number of points.
Function adaptiveIntegral(f,a,b,precision,remainingInterations)
if remainingIterations = 0 then
Print "Adaptive integration failed on the interval [a,b]"
Return(-1)
exit
endif
R = numericalIntegral(f,a,b)
S = numericalIntegral(f,a,(a+b)/2)
T = numericalIntegral(f,(a+b)/2,b)
if abs(R-(S+T)) < precision then
return(S+T)
else
return(adaptiveIntegral(f,a,(a+b)/2,precision,remainingInterations-1)
+adaptiveIntegral(f,(a+b)/2,b,precision,remainingInterations-1))
endif
end
Let's try this in Mathematica. We will use the 20-point Gauss-Legendre method for numericalIntegral. I'm going to add a
line to trace the iterations. I'm also going to eliminate a major inefficiency. In the pseudocode, when we call adaptive-
Integral(f,a,(a+b)/2,precision,remainingInterations-1) , we calculate numericalIntegral(f,a,(a+b)/2). Be we calculated that
just before the recursive call, so let's pass the value as part of the recursion.
improper_integrals.nb 7
In[108]:=
adaptiveIntegral@f_, a_, b_, integralA2B_,
8r, s, t<,
precision_, remainingIterations_, firstIteration_D := Module@
Return@−1D,
If@firstIteration,
r = gaussLegendre@f, a, b, gc20D,
r = integralA2B
D;
s = gaussLegendre@f, a, Ha + bL ê 2, gc20D;
t = gaussLegendre@f, Ha + bL ê 2, b, gc20D;
H∗ Print@8a,b,Abs@r−Hs+tLD<D; ∗L
If@Abs@r − Hs + tLD < precision,
Return@s + tD,
Let's try it on
‡ ÅÅÅÅÅÅÅÅ
è!!!ÅÅÅÅÅ „ x = 2
1
1
0 x
In[109]:=
adaptiveIntegral@f, 0, 1, 0, 0.0001, 20, TrueD
Out[109]=
1.99977
In[111]:=
adaptiveIntegral@g, 0, 1, 0, 0.0001, 20, TrueD