\chapter[Techniques of Integration III]{Techniques of Integration III: Rational Functions}

In this section we treat \index{integration of {\bf rational functions}} integration of {\bf rational functions}.  A
``rational function'' is a fraction with polynomials in the numerator and
denominator.  For example, 
\[
\frac{x^3}{ x^2+x-6},
\qquad\qquad
\frac{1}{ (x-3)^2},
\qquad\qquad
\frac{x^2+1}{ x^2-1}
\]
are all rational functions of $x$.  There is a general technique called
``\index{partial fractions} partial fractions'' for integrating a rational function.  The algebraic
steps in that technique are rather cumbersome if the polynomial in the
denominator has degree more than 2 (except in the case when the denominator
has the form $(ax+b)^n$, a case we shall treat below).  However, in
practice one does not often run across rational functions with high degree
polynomials in the denominator for which one has to find the
antiderivative function.  So we shall explain how to find the
antiderivative of a rational function only in the two cases which are most
frequently encountered: (a) the denominator has the form $(ax+b)^n$; (b)
the denominator is a quadratic polynomial $ax^2+bx+c$.

\smallskip

In the case when the denominator has the form $(ax+b)^n$, the
$u$-substitution $u=ax+b$ will always work.  Just replace the denominator
by $u^n$, replace $x$ in the numerator by $(u-b)/a$, and replace $dx$ by
$\frac{1}{ a}du$.


\begin{example}
%{\bf Example 1.} 
Find $$\int_0^1\frac{t^3dt}{(3-2t)^2}.$$

\smallskip

We set $u=3-2t$, so that $t=(3-u)/2$, $dt=-\frac{1}{ 2}du$.  The limits of
integration change: $t=0\Longrightarrow u=3$, and $t=1\Longrightarrow u=1$.
So we obtain:
\begin{align*} 
-\frac{1}{ 2}\int_3^1  \left(\frac{3-u}{ 2}\right)^3\,\frac{du}{ u^2}
&= -\frac{1}{ 16}\int_3^1\frac{(3-u)^3}{ u^2}\,du
=\frac{1}{ 16}\int_1^3\frac{ 27-27u+9u^2-u^3}{ u^2}\,du\\ 
&=\frac{1}{ 16}\int_1^3\left(\frac{27}{ u^2}-\frac{27}{ u}+9-u\right)\,du \\
&=\frac{1}{ 16}\left(-\frac{27}{ u}-27\ln u+9u-\frac{1}{2}u^2\right)
\Bigm|_1^3=2-\frac{27}{ 16}\ln 3.
\end{align*} 

\end{example}

\medskip

We now proceed to the case when the denominator is a quadratic polynomial.
We can always factor out the coefficient of $x^2$ and put it outside the
integral.  This will lead to a denominator in which $x^2$ has coefficient
1, i.e., a denominator of the form $x^2+bx+c$.  There are three possible
cases, depending on how many real roots the quadratic has.  Recall the
quadratic formula used to solve $ax^2+bx+c=0$, which when $a=1$ takes the
form $r_1,r_2=(-b\pm\sqrt{b^2-4c})/2$.  The sign of the discriminant
$b^2-4c$ tells us whether there is (a) 1 double root (when the discriminant
is 0), (b) two distinct roots (when the discriminant is positive), or (c)
no real roots (when the discriminant is negative).  In the first case, the
denominator takes the form $(x-r)^2$, and we can integrate the rational
function by the method explained above (substituting $u=x-r$).  The
remainder of this section is concerned with the other two possibilities.


\section[Quadratic denominator factors]{Quadratic Denominator That Factors} 
We first make an algebraic
observation about what happens when we subtract as follows: 
\[
\frac{1}{ x-r_1}-\frac{1}{ x-r_2}
=\frac{1}{ x-r_1}\cdot\frac{x-r_2}{ x-r_2}
-\frac{1}{x-r_2}\cdot\frac{x-r_1}{ x-r_1}
=\frac{r_1-r_2}{(x-r_1)(x-r_2)}.
\]
We shall use this in the reverse order: instead of combining $1/(x-r_1)$
and $1/(x-r_2)$ into a single fraction, we shall split up
$1/(x-r_1)(x-r_2)$ into a difference of two fractions.  Namely, we divide
through by $r_1-r_2$ in the above equality:
\[
\frac{1}{(x-r_1)(x-r_2)}
=\frac{1}{ r_1-r_2}\left(\frac{1}{ x-r_1}-\frac{1}{x-r_2} \right).
\]
This basic algebraic identity will allow us to split up our
integral into two separate integrals, in each of which the denominator has
the simpler form $x-r$.  Here are some examples.


\begin{example}
%{\bf Example 2.} 
Find $$\int_1^\infty\frac{dx}{2x^2+x}.$$

\smallskip

Since $2x^2+x=2(x^2+0.5)=2(x-0)(x-(-0.5))$, we take $r_1=0$, $r_2=-0.5$.  Then 
\[
\frac{1}{2x^2+x}=\frac{1}{2}\cdot\frac{1}{x^2+0.5}=\frac{1}{2}\cdot
\frac{1}{ 0-(-0.5)}\left(\frac{1}{ x-0}-\frac{1}{ x-(-0.5)}\right) =
\left(\frac{1}{ x}-\frac{1}{ x+0.5}\right).
\]
Thus, our integral is 
\[
\int_1^\infty\left(\frac{1}{ x}-\frac{1}{ x+0.5}\right)dx
= \bigl(\ln x-\ln(x+0.5)\bigr)\Bigm|_1^\infty.
\]
(We used the formula $\int dx/(ax+b)=\frac{1}{ a}\ln|ax+b|+C$, and we omitted
the absolute value signs, because both $x$ and $x+0.5$ are positive between
$1$ and $\infty$.)  To evaluate this antiderivative at $\infty$ means to
take the limit of $\ln b-\ln(b+0.5)$ as $b\longrightarrow\infty$.  Both $\ln
b$ and $\ln(b+0.5)$ approach $\infty$, so we have the indeterminate form
$\infty-\infty$.  Write $\ln b-\ln(b+0.5)=\ln\left(\frac{b}{ b+0.5}\right)$.
Notice that $b/(b+0.5)$ has limit 1 as
$b\longrightarrow\infty$.  Thus, its ln has limit $\ln 1=0$.  In other
words, evaluating $\ln x-\ln(x+0.5)$ at $\infty$ gives 0.  Thus, we conclude
that $\int_1^\infty dx/(2x^2+x)=-(\ln 1-\ln 1.5)=\ln 1.5$.

\end{example}

\begin{example}
%{\bf Example 3.} 
Find the $x$-coordinate of the center of mass of the
uniform flat plate bounded by the $x$- and $y$-axes, the line $x=2$, and
the curve $y=1/(9-x^2)$.

\smallskip

Here $\overline{x}$ is the ratio of the integral $\int_0^2 x\,dx/(9-x^2)$
to the integral $\int_0^2dx/(9-x^2)$.  We first factor out the coefficient
of $x^2$, which is $-1$, and write $9-x^2=-(x^2-9)=-(x+3)(x-3)$.  Thus,
\begin{align*}
\frac{1}{ 9-x^2}
&=-\frac{1}{(x-(-3))(x-3)}
=-\frac{1}{ (-3)-3}\left(\frac{1}{ x-(-3)}-\frac{1}{ x-3}\right)\\
&=\frac{1}{ 6}\left(\frac{1}{ x+3}-\frac{1}{ x-3}\right).
\end{align*}
 So the bottom integral is 
\[
\frac{1}{ 6}\int_0^2\left(\frac{1}{x+3}-\frac{1}{ x-3}\right)dx
=\frac{1}{ 6}\left(\ln(x+3)-\ln|x-3|\right) \Bigm|_0^2.
\]
(We need absolute values because $x-3$ is negative for
$x$ between 0 and 2.)  The result is $\frac{1}{ 6}\ln 5$.

\smallskip

The top integral is the same, except with an $x$, i.e., 
\[
\frac{1}{6}\int_0^2\left(\frac{x}{ x+3}-\frac{x}{ x-3}\right)dx,
\]
and we could integrate each of these terms without difficulty.  However, in
this particular integral there happens to be an easier way: notice that in
the original integral $\int_0^2x\,dx/(9-x^2)$ the derivative of $9-x^2$ is
essentially what we have in the numerator.  Hence, it is more efficient
simply to substitute $u=9-x^2$, thereby transforming the top integral as
follows ($du=-2x\,dx$, and the limits of integration become $9-0^2=9$ to
$9-2^2=5$): 
\[
-\frac{1}{ 2}\int_9^5\frac{du}{ u}
=-\frac{1}{ 2}(\ln 5 -\ln 9)
=\frac{1}{ 2}(\ln 9-\ln 5)=\frac{1}{ 2}\ln 1.8.
\] 
Finally, $\overline{x}=\frac{1}{ 2}\ln 1.8
\bigm/\frac{1}{ 6}\ln 5=3\ln 1.8/\ln 5=1.0956$.
\end{example}

\begin{example}
%{\bf Example 4.} 
Find the antiderivative of $x^4/(x^2-x-2)$.

\smallskip

If the numerator has degree 2 or more, then you can simplify the integral
by first performing a long division of polynomials.  In this case you get
$x^4$ divided by $x^2-x-2$ is $x^2+x+3$ with a remainder of $5x+6$.  Thus,
the integral is 
\[
   \int \left(x^2+x+3+\frac{5x+6}{ x^2-x-2}\right)dx.
\]
 To
handle the fraction, we factor $x^2-x-2=(x-2)(x+1)$.  (If you can't see the
factorization by inspection, then use the quadratic formula to determine
the roots, which in this case are 2 and $-1$.)  Then 
\[
\frac{5x+6}{ x^2-x-2}
=(5x+6)\cdot\frac{1}{ 2-(-1)}\left(\frac{1}{ x-2}-\frac{1}{ x+1}\right)
=\frac{1}{ 3}\left(\frac{5x+6}{ x-2}-\frac{5x+6}{ x+1}\right).
\]
Thus,
the problem boils down to integrating $(5x+6)/(x-2)$ and $(5x+6)/(x+1)$.
These integrals are done by the method described at the beginning of this
section.  For example, substituting $u=x-2$ in the first integral, we have:
\begin{align*}
\int\frac{5x+6}{ x-2}\,dx
&=\int\frac{5(u+2)+6}{ u}du=\int\left(5+\frac{16}{ u}\right)\, du\\
&=5u+16\ln|u|+C=5(x-2)+16\ln|x-2|+C.
\end{align*} The integral of $(5x+6)/(x+1)$ is similar.

\end{example}


\section[Denominator does not factor]{Quadratic Denominator That Does Not Factor} 

As a preliminary procedure, we first factor out the coefficient of $x^2$,
so that the quadratic denominator has the form $x^2+bx+c$.  If the
numerator has degree 2 or greater, we then use long division of polynomials
to write our rational function in the form $$\text{polynomial}+\frac{\alpha
x+\beta}{ x^2+bx+c}.$$ Next, we ``complete the square'' in the
denominator: $x^2+bx+c=\left(x+\frac{1}{ 2}b\right)^2+(c-\frac{1}{ 4}b^2)$, and
we set $r=\sqrt{c-\frac{1}{ 4}b^2}$, so that $x^2+bx+c=\left(x+\frac{1}{ 2}b
\right)^2+r^2$.  After a $u$-substitution of the form $u=x+\frac{1}{ 2}b$, we
can transform the integral to a sum of two integrals of the form 
\[
\int \frac{u\,du}{ u^2+r^2}=
\frac{1}{ 2}\ln(u^2+r^2)+C,
\qquad\text{and}\qquad
\int\frac{du}{ u^2+r^2}=
\frac{1}{ r}\text{Arctan}\left(\frac{u}{ r}\right)+C.
\]

We illustrate with two examples.  In Example 14.5 we will already have the
denominator in the form $x^2+1$, so we do not make a $u$-substitution.  In
Example 14.6 we will have to do some algebra to get the integral in the two
standard forms $\int u\,du/(u^2+r^2)$ and $\int du/(u^2+r^2)$.


\begin{example}
%{\bf Example 5.} 
Integrating $x^n\text{Arctan}\,x$.

\smallskip

Applying integration by parts in accordance with the table in the last
section (setting $v'(x)=x^n$ and $u(x)=\text{Arctan}\,x$), we obtain 
\[
\int x^n\text{Arctan}\,x\,dx
     =\frac{x^{n+1}}{ n+1}\text{Arctan}\,x
          -\frac{1}{ n+1}\int\frac{x^{n+1}}{1+x^2}\,dx.
\]
To evaluate the last integral, divide
$x^2+1$ into $x^{n+1}$, obtaining a polynomial quotient and a remainder.
It turns out that the remainder will be $x$ or $-x$ if $n$ is an even
number, and 1 or $-1$ if $n$ is an odd number.  Thus, after integrating the
polynomial quotient, you will be left with either 
$\int x\,dx/(x^2+1)=\frac{1}{ 2}\ln(x^2+1)+C$, or else 
$\int dx/(x^2+1)$ =$\text{Arctan}\,x+C$. 

\end{example}


\begin{example}
%{\bf Example 6.} 
Find the antiderivative of $x^3/(x^2+2x+5)$.

\smallskip

First, $x^3$ divided by $x^2+2x+5$ is $x-2$ with a remainder of $-x+10$.
Next, completing the square gives $x^2+2x+5=(x+1)^2+4=(x+1)^2+2^2$, and so
we substitute $u=x+1$ (then $x=u-1$, $dx=du$).  Thus,
\begin{align*} 
\int\frac{x^3dx}{ x^2+2x+5}
&=\int\left(x-2+\frac{-x+10}{ x^2+2x+5} \right)\,dx\\
&=\frac{1}{ 2}x^2-2x+\int\frac{-x+10}{ (x+1)^2+4}\,dx\\
&=\frac{1}{ 2}x^2-2x +\int\frac{-(u-1)+10}{ u^2+4}\,du\\
&=\frac{1}{2}x^2-2x-\int\frac{u\,du}{ u^2+4}+{11}\int\frac{du}{ u^2+4}\\ 
&=\frac{1}{ 2}x^2-2x-\frac{1}{ 2}\ln(u^2+4)
+\frac{11}{ 2}\text{Arctan}\left(\frac{u}{2}\right)+C\\ 
&=\frac{1}{ 2}x^2-2x-\frac{1}{ 2}\ln(x^2+2x+5)
+\frac{11}{2}\text{Arctan}\left(\frac{x+1}{ 2}\right)+C.
\end{align*} 

\end{example}
% 
