Home TOC Font Previous Next

5.3. Methods of Integration

Change of Variable

Sometimes an unfamiliar-looking integral can be made into a familiar one by substituting a new variable for an old one. For example, we know how to integrate 1/x --- the answer is ln x --- but what about

\[\int \frac{dx}{2x+1} \hspace{10pt}?\]

Let u=2x+1. Differentiating both sides, we have du=2dx, or dx=du/2, so

\begin{align} \int \frac{dx}{2x+1} &= \int \frac{du/2}{u} \\ &= \frac{1}{2}\ln u + c \\ &= \frac{1}{2}\ln (2x+1) +c . \end{align}

This technique is known as a change of variable or a substitution. (Because the letter u is often employed, you may also see it called u-substitution.)

In the case of a definite integral, we have to remember to change the limits of integration to reflect the new variable.

Example 64

◊ Evaluate \(\int_3^4 dx/(2x+1)\).

◊ As before, let u=2x+1.

\begin{align} \int_{x=3}^{x=4} \frac{dx}{2x+1} &= \int_{u=7}^{u=9} \frac{du/2}{u} \\ &= \left.\frac{1}{2}\ln u\right|_{u=7}^{u=9} \end{align}

Here the notation \(\left.\right|_{u=7} ^{u=9}\) means to evaluate the function at 7 and 9, and subtract the former from the latter. The result is

\begin{align} \int_{x=3}^{x=4} \frac{dx}{2x+1} &= \frac{1}{2}(\ln 9 - \ln 7) \\ &= \frac{1}{2}\ln \frac{9}{7} \end{align}

Sometimes, as in the next example, a clever substitution is the secret to doing a seemingly impossible integral.

Example 65

◊ Evaluate

\[ \int \frac{e^{\sqrt x}}{\sqrt x} dx . \]

◊ The only hope for reducing this to a form we can do is to let \(u=\sqrt x\). Then dx = d(u2) = 2udu, so

\begin{align} \int \frac{e^{\sqrt x}}{\sqrt x} dx &= \int \frac{e^u}{u} \cdot 2udu \\ &= 2 \int e^u du \\ &= 2e^u \\ &= 2e^{\sqrt{x}} . \end{align}

Example 65 really isn't so tricky, since there was only one logical choice for the substitution that had any hope of working. The following is a little more dastardly.

Example 66

◊ Evaluate

\[ \int \frac{dx}{1+x^2} . \]

◊ The substitution that works is x=tan u. First let's see what this does to the expression 1+x2. The familiar identity

\[ \sin^2 u + \cos^2 u = 1 \]

when divided by \( \cos^2 u\), gives

\[ \tan^2 u + 1 = \sec^2 u \hspace{10pt},\]

so 1+x2 becomes \(\sec^2 u\). But differentiating both sides of x=tan u gives

\begin{align} dx &= d \left[\sin u(\cos u)^{-1}\right] \\ &= (d\sin u)(\cos u)^{-1} \\ & +(\sin u)d\left[(\cos u)^{-1}\right] \\ &= \left(1+\tan^2 u\right)du \\ &= \sec^2 udu , \end{align}

so the integral becomes

\begin{align} \int \frac{dx}{1+x^2} &= \int \frac{\sec^2 u du}{\sec^2 u} \\ &= u+c \\ &= \tan^{-1} x+c . \end{align}

What mere mortal would ever have suspected that the substitution x=tan u was the one that was needed in Example 66? One possible answer is to give up and do the integral on a computer:

   Integrate(x) 1/(1+x^2)
      ArcTan(x) 

Another possible answer is that you can usually smell the possibility of this type of substitution, involving a trig function, when the thing to be integrated contains something reminiscent of the Pythagorean theorem, as suggested by Figure B. The 1+x2 looks like what you'd get if you had a right triangle with legs 1 and x, and were using the Pythagorean theorem to find its hypotenuse.

tan-substitution
Figure B. The substitution x=tan u.

Example 67

◊ Evaluate \(\int dx/\sqrt{1-x^2}\).

◊ The \(\sqrt{1-x^2}\) looks like what you'd get if you had a right triangle with hypotenuse 1 and a leg of length x, and were using the Pythagorean theorem to find the other leg, as in Figure C. This motivates us to try the substitution x=cos u, which gives dx = -sin udu and \(\sqrt{1-x^2}=\sqrt{1-\cos^2u}=\sin u\). The result is

\begin{align} \int \frac{dx}{\sqrt{1-x^2}} &= \int \frac{-\sin udu}{\sin u} \\ &= -u+c \\ &= -\cos^{-1}x . \end{align}

cos-substitution
Figure C. The substitution x=cos u.

Integration by Parts

Figure D shows a technique called integration by parts. If the integral \(\int vdu\) is easier than the integral \(\int udv\), then we can calculate the easier one, and then by simple geometry determine the one we wanted. Identifying the large rectangle that surrounds both shaded areas, and the small white rectangle on the lower left, we have

\begin{align} \int udv &= (\text{area of large rectangle}) \\ &- (\text{area of small rectangle}) \\ &- \int vdu . \end{align}

by-parts
Figure D. Integration by parts.

In the case of an indefinite integral, we have a similar relationship derived from the product rule:

\begin{align} d(uv) &= u dv + v du \\ u dv &= d(uv) - v du \end{align}

Integrating both sides, we have the following relation.

Integration by Parts

\[ \int u dv = uv - \int v du . \]

Since a definite integral can always be done by evaluating an indefinite integral at its upper and lower limits, one usually uses this form. Integrals don't usually come prepackaged in a form that makes it obvious that you should use integration by parts. What the equation for integration by parts tells us is that if we can split up the integrand into two factors, one of which (the dv) we know how to integrate, we have the option of changing the integral into a new form in which that factor becomes its integral, and the other factor becomes its derivative. If we choose the right way of splitting up the integrand into parts, the result can be a simplification.

Example 68

◊ Evaluate

\[ \int x \cos x dx \]

◊ There are two obvious possibilities for splitting up the integrand into factors,

\[ u dv = (x)(\cos xdx) \]

or

\[ u dv = (\cos x)(xdx) \]

The first one is the one that lets us make progress. If u=x, then du=dx, and if dv = cos xdx, then integration gives v=sin x.

\begin{align} \int x \cos x dx &= \int u dv \\ &= uv - \int v du \\ &= x\sin x-\int \sin x dx \\ &= x\sin x+\cos x \end{align}

Of the two possibilities we considered for u and dv, the reason this one helped was that differentiating x gave dx, which was simpler, and integrating cos xdx gave sin x, which was no more complicated than before. The second possibility would have made things worse rather than better, because integrating xdx would have given x2/2, which would have been more complicated rather than less.

Example 69

◊ Evaluate \(\int \ln x dx\).

◊ This one is a little tricky, because it isn't explicitly written as a product, and yet we can attack it using integration by parts. Let u=ln x and dv=dx.

\begin{align} \int \ln x dx &= \int u dv \\ &= uv - \int v du \\ &= x\ln x-\int x \frac{dx}{x} \\ &= x\ln x-x \end{align}

Example 70

◊ Evaluate \(\int x^2 e^x dx\).

◊ Integration by parts lets us split the integrand into two factors, integrate one, differentiate the other, and then do that integral. Integrating or differentiating ex does nothing. Integrating x2 increases the exponent, which makes the problem look harder, whereas differentiating x2 knocks the exponent down a step, which makes it look easier. Let u=x2 and dv=ex dx, so that du=2xdx and v=ex. We then have

\[ \int x^2 e^x dx = x^2 e^x - 2 \int x e^xdx . \]

Although we don't immediately know how to evaluate this new integral, we can subject it to the same type of integration by parts, now with u=x and dv=ex dx. After the second integration by parts, we have:

\begin{align} \int x^2 e^x dx &= x^2 e^x - 2 \left(x e^x -\int e^xdx \right) \\ &= x^2 e^x - 2 \left(x e^x - e^x \right) \\ &= (x^2-2x+2)e^x \end{align}

Partial Fractions

Given a function like

\[\frac{-1}{x-1}+\frac{1}{x+1} ,\]

we can rewrite it over a common denominator like this:

\begin{align} & \left(\frac{-1}{x-1}\right)\left(\frac{x+1}{x+1}\right) \\ & +\left(\frac{1}{x+1}\right)\left(\frac{x-1}{x-1}\right) \\ &= \frac{-x-1+x-1}{(x-1)(x+1)} \\ &=\frac{-2}{x^2-1} . \end{align}

But note that the original form is easily integrated to give

\begin{align} \int \left(\frac{-1}{x-1}+\frac{1}{x+1}\right)dx =-\ln(x-1)+\ln(x+1)+c , \end{align}

while faced with the form -2/(x2-1), we wouldn't have known how to integrate it.

Note that the original function was of the form (-1)/…+(+1)/… It's not a coincidence that the two constants on top, -1 and +1, are opposite in sign but equal in absolute value. To see why, consider the behavior of this function for large values of x. Looking at the form -1/(x-1)+1/(x+1), we might naively guess that for a large value of x such as 1000, it would come out to be somewhere on the order thousandths. But looking at the form -2/(x2-1), we would expect it to be way down in the millionths. This seeming paradox is resolved by noting that for large values of x, the two terms in the form -1/(x-1) + 1/(x+1) very nearly cancel. This cancellation could only have happened if the constants on top were opposites like plus and minus one.

The idea of the method of partial fractions is that if we want to do an integral of the form

\[\int \frac{dx}{P(x)} ,\]

where P(x) is an nth order polynomial, we rewrite 1/P as

\[\frac{1}{P(x)} = \frac{A_1}{x-r_1} + ... \frac{A_n}{x-r_n} ,\]

where r1 ... rn are the roots of the polynomial, i.e., the solutions of the equation P(r)=0. If the polynomial is second-order, you can find the roots r1 and r2 using the quadratic formula; I'll assume for the time being that they're real. For higher-order polynomials, there is no surefire, easy way of finding the roots by hand, and you'd be smart simply to use computer software to do it. In Yacas, you can find the real roots of a polynomial like this:

   FindRealRoots(x^4-5*x^3
      -25*x^2+65*x+84)
  {3.,7.,-4.,-1.} 

(I assume it uses Newton's method to find them.) The constants Ai can then be determined by algebra, or by the following trick.

Numerical Method

Suppose we evaluate 1/P(x) for a value of x very close to one of the roots. In the example of the polynomial x4 - 5x3 - 25x2 + 65x + 84, let r1 ... r4 be the roots in the order in which they were returned by Yacas. Then A1 can be found by evaluating 1/P(x) at x = 3.000001:

   P(x):=x^4-5*x^3-25*x^2
     +65*x+84
   N(1/P(3.000001))
     -8928.5702094768 

We know that for x very close to 3, the expression

\[ \frac{1}{P} = \frac{A_1}{x-3}+\frac{A_2}{x-7}+\frac{A_3}{x+4}+\frac{A_4}{x+1}\]

will be dominated by the A1 term, so

\begin{align} -8930 & \approx \frac{A_1}{3.000001-3} \\ A_1 & \approx (-8930)(10^{-6}) . \end{align}

By the same method we can find the other four constants:

   dx:=.000001
   N(1/P(7+dx),30)*dx
      0.2840908276e-2 
   N(1/P(-4+dx),30)*dx
      -0.4329006192e-2 
   N(1/P(-1+dx),30)*dx
      0.1041666664e-1 

(The N( ,30) construct is to tell Yacas to do a numerical calculation rather than an exact symbolic one, and to use 30 digits of precision, in order to avoid problems with rounding errors.) Thus,

\begin{align} \frac{1}{P} &= \frac{-8.93\times10^{-3}}{x-3} \\ & + \frac{2.84\times10^{-3}}{x-7} \\ & - \frac{4.33\times10^{-3}}{x+4} \\ & + \frac{1.04\times10^{-2}}{x+1} . \end{align}

The desired integral is

\begin{align} \int \frac{dx}{P(x)} &= -8.93\times10^{-3}\ln(x-3) \\ & +2.84\times10^{-3}\ln(x-7) \\ & -4.33\times10^{-3}\ln(x+4) \\ & + 1.04\times10^{-2}\ln(x+1) \\ & + c . \end{align}

As in the simpler example I started off with, where P was second order and we got A1 = -A2, in this n=4 example we expect that A1 + A2 + A3 + A4 = 0, for otherwise the large-x behavior of the partial-fraction form would be 1/x rather than 1/x4. This is a useful way of checking the result: -8.93 + 2.84-4.33 + 10.4 = -.02 ≈ 0.

Complications

There are two possible complications:

First, the same factor may occur more than once, as in x3 - 5x2 + 7x-3 = (x-1)(x-1)(x-3). In this example, we have to look for an answer of the form A/(x-1) + B/(x-1)2 + C/(x-3), the solution being -.25/(x-1) - .5/(x-1)2 + .25/(x-3).

Second, the roots may be complex. This is no show-stopper if you're using computer software that handles complex numbers gracefully. (You can choose a c that makes the result real.) In fact, as discussed in section 8.3, some beautiful things can happen with complex roots. But as an alternative, any polynomial with real coefficients can be factored into linear and quadratic factors with real coefficients. For each quadratic factor Q(x), we then have a partial fraction of the form (A+Bx)/Q(x), where A and B can be determined by algebra. In Yacas, this can be done using the Apart function.

Example 71

◊ Evaluate the integral

\[ \int \frac{dx}{(x^4 - 8x^3 + 8x^2 - 8x + 7} \]

using the method of partial fractions.

◊ First we use Yacas to look for real roots of the polynomial:

   FindRealRoots(x^4-8*x^3
     +8*x^2-8*x+7)
     {1.,7.} 

Unfortunately this polynomial seems to have only two real roots; the rest are complex. We can divide out the factor (x-1)(x-7), but that still leaves us with a second-order polynomial, which has no real roots. One approach would be to factor the polynomial into the form (x-1)(x-7)(x-p)(x-q), where p and q are complex, as in section 8.3. Instead, let's use Yacas to expand the integrand in terms of partial fractions:

   Apart(1/(x^4-8*x^3
     +8*x^2-8*x+7))
       ((2*x)/25+3/50)/(x^2+1) 
         +1/(300*(x-7)) 
            +(-1)/(12*(x-1)) 

We can now rewrite the integral like this:

\begin{align} & \frac{2}{25} \int \frac{xdx}{x^2+1} \\ &+ \frac{3}{50} \int \frac{dx}{x^2+1} \\ &+ \frac{1}{300} \int \frac{dx}{x-7} \\ &- \frac{1}{12} \int \frac{dx}{x-1} \end{align}

which we can evaluate as follows:

\begin{align} & \frac{1}{25} \ln(x^2+1) \\ & + \frac{3}{50} \tan^{-1}x \\ &+ \frac{1}{300} \ln(x-7) \\ &- \frac{1}{12} \ln(x-1) \\ & +c \end{align}

In fact, Yacas should be able to do the whole integral for us from scratch, but it's best to understand how these things work under the hood, and to avoid being completely dependent on one particular piece of software. As an illustration of this gem of wisdom, I found that when I tried to make Yacas evaluate the integral in one gulp, it choked because the calculation became too complicated! Because I understood the ideas behind the procedure, I was still able to get a result through a mixture of computer calculations and working it by hand. Someone who didn't have the knowledge of the technique might have tried the integral using the software, seen it fail, and concluded, incorrectly, that the integral was one that simply couldn't be done. A computer is no substitute for understanding.

Residue Method

On p. 92 I introduced the trick of carrying out the method of partial fractions by evaluating 1/P(x) numerically at x = ri+ε, near where 1/P blows up. Sometimes we would like to have an exact result rather than a numerical approximation. We can accomplish this by using an infinitesimal number dx rather than a small but finite ε. For simplicity, let's assume that all of the n roots ri are distinct, and that P's highest-order term is xn. We can then write P as the product P(x) = (x-r1)(x-r2)…(x-rn). For products like this, there is a notation Π (capital Greek letter “pi”) that works like Σ does for sums:

\[P(x)=\prod_{i=1}^n(x-r_i) .\]

It's not necessary that the roots be real, but for now we assume that they are. We want to find the coefficients Ai such that

\[\frac{1}{P(x)} = \sum \frac{A_i}{x-r_i} .\]

We then have

\begin{align} \frac{1}{P(r_i+dx)} &= \frac{1}{dx \prod_{j\ne i}(r_i-r_j+dx)} \\ &= \frac{1}{dx \prod_{j\ne i}(r_i-r_j)} + ... \\ &= \frac{A_i}{dx}+... , \end{align}

where … represents finite terms that are negligible compared to the infinite ones. Multiplying on both sides by dx, we have

\[\frac{1}{P'(r_i)} + ... = A_i + ... ,\]

where the … now stand for infinitesimals which must in fact cancel out, since both Ai and 1/P' are real numbers.

Example 72

◊ The partial-fraction decomposition of the function

\[ \frac{1}{x^4-5x^3-25x^2+65x+84} \]

was found numerically on p. 92. The coefficient of the 1/(x-3) term was found numerically to be A1 ≈ -8.930×10-3. Determine it exactly using the residue method.

◊ Differentiation gives P'(x) = 4x3-15x2-50x+65. We then have A1 = 1/P'(3) = -1/112.

Integrals That Can't be Done

Integral calculus was invented in the age of powdered wigs and harpsichords, so the original emphasis was on expressing integrals in a form that would allow numbers to be plugged in for easy numerical evaluation by scribbling on scraps of parchment with a quill pen. This was an era when you might have to travel to a large city to get access to a table of logarithms.

In this computationally impoverished environment, one always wanted to get answers in what's known as closed form and in terms of elementary functions.

A closed form expression means one written using a finite number of operations, as opposed to something like the geometric series 1+x+x2+x3+…, which goes on forever.

Elementary functions are usually taken to be addition, subtraction, multiplication, division, logs, and exponentials, as well as other functions derivable from these. For example, a cube root is allowed, since \(\sqrt[3]x = e^{(1/3)\ln x}\), and so are trig functions and their inverses, since, as we will see in chapter 8, they can be expressed in terms of logs and exponentials.

In theory, “closed form” doesn't mean anything unless we state the elementary functions that are allowed. In practice, when people refer to closed form, they usually have in mind the particular set of elementary functions described above.

A traditional freshman calculus course spends such a vast amount of time teaching you how to do integrals in closed form that it may be easy to miss the fact that this is impossible for the vast majority of integrands that you might randomly write down. Here are some examples of impossible integrals:

\begin{align} & \int e^{-x^2} dx \\ & \int x^x dx \\ & \int \frac{\sin x}{x} dx \\ & \int e^x \tan x dx \end{align}

The first of these is a form that is extremely important in statistics (it describes the area under the standard “bell curve”), so you can see that impossible integrals aren't just obscure things that don't pop up in real life.

People who are proficient at doing integrals in closed form generally seem to work by a process of pattern matching. They recognize certain integrals as being of a form that can't be done, so they know not to try.

Example 73

◊ Students! Stand at attention! You will now evaluate \(\int e^{-x^2+7x} dx\) in closed form.

◊ No sir, I can't do that. By a change of variables of the form u=x+c, where c is a constant, we could clearly put this into the form \(\int e^{-x^2} dx\) , which we know is impossible.

Sometimes an integral such as \(\int e^{-x^2} dx\) is important enough that we want to give it a name, tabulate it, and write computer subroutines that can evaluate it numerically. For example, statisticians define the “error function” \(\operatorname{erf}(x)=(2/\sqrt{\pi}) \int e^{-x^2} dx\). Sometimes if you're not sure whether an integral can be done in closed form, you can put it into computer software, which will tell you that it reduces to one of these functions. You then know that it can't be done in closed form. For example, if you ask the popular web site integrals.com to do \(\int e^{-x^2+7x} dx\), it spits back \((1/2)e^{49/4}\sqrt{\pi}\operatorname{erf}(x-7/2)\). This tells you both that you shouldn't be wasting your time trying to do the integral in closed form and that if you need to evaluate it numerically, you can do that using the erf function.

As shown in the following example, just because an indefinite integral can't be done, that doesn't mean that we can never do a related definite integral.

Example 74

◊ Evaluate \(\int_0^{\pi/2} e^{-\tan^2 x}(\tan^2x+1)dx\).

◊ The obvious substitution to try is u=tan x, and this reduces the integrand to e-x2. This proves that the corresponding indefinite integral is impossible to express in closed form. However, the definite integral can be expressed in closed form; it turns out to be \(\sqrt{\pi}/2\). The trick for proving this is given in Example 99 on p. 134.

Sometimes computer software can't say anything about a particular integral at all. That doesn't mean that the integral can't be done. Computers are stupid, and they may try brute-force techniques that fail because the computer runs out of memory or CPU time. For example, the integral \(\int dx/(x^{10000}-1)\) (problem 15, p. 127) can be done in closed form using the techniques of chapter 8, and it's not too hard for a proficient human to figure out how to attack it, but every computer program I've tried it on has failed silently.