VII.F Integrating Rational Functions
VII.F Integration of Rational Functions
© M. Flashman
Dec., 2005: This page now requires Internet Explorer 6+MathPlayer or Mozilla/Firefox/Netscape 7+.
As we have seen in the preceeding work, finding an indefinite integral is often as much a matter of skill and perception as knowledge. The only class of functions which we can say is trivial to integrate is the class of polynomial functions. In this section we will outline a systematic approach for handling the only other large class of functions for which there is a fairly complete algorithm for integration. This class of functions is formed by the ratios of polynomials, i.e., the rational functions. To begin we'll examine some simple but typical examples of rational functions that we can integrate already.

Here are some of the integrals we've discovered already:
 

`int 1/x dx = ln|x| + C` `int 1/(x^2)dx = -1/x + C`
`int 1/(1+x^2) dx = text{arc}tan(x) + C` `int (2x) /(1+x^2) dx = ln(1+x^2) + C`

The next examples illustrate the key ideas for more general problems.
Example VII.F.1: Find `int (x^2 + 3x + 5)/(x-1) dx`.
Solution: The first thing to notice here is that the polynomial in the numerator of this rational function has degree 2 while the polynomial in the denominator has degree 1. A quotient of polynomials where the degree of the numerator is greater than or equal to the degree of the denominator is called an improper fraction and is simplified by the long division of these two polynomials as follows:

        `text{         }x + 4`
`x-1 |bar{   x^2 + 3x + 5 }`
`text{  }- (x^2  -  x)  `
`text{          } bar{text{         }4x + 5   }`
  `text{          }        -(4x - 4)`
 `text{               }        bar{text{                   } 9

Thus `(x^2 + 3x + 5)/(x - 1) = x + 4 + (9)/(x-1)` and the final integration result can be obtained by using linearity and a simple substitution: [You should fill in the details.]

`int (x^2 + 3x + 5)/(x -1) dx = (x^2)/2 + 4x + 9 ln|x -1| + C`

Example VII.F.2: Find `int (x^3)/(x^2 + 1) dx.
Solution: Here is another example of an improper fraction which will be solved by long division and linearity.
 
      ` text{                 }x `
 ` x^2 + 1 |bar{  x^3 text{      }   }`
`text{         }-(x^3 + x)`
 `text{           }bar{text{         }- x}`

Thus `(x^3)/(x^2 + 1) = x - (x)/(x^2 + 1)` and we have the result (details omitted )

`int  (x^3)/(x^2 + 1) dx = (x^2)/(2) - (1/2) ln(x^2 + 1) + C `
Example VII.F.3: Find `int 1/(x^2 + 6x + 13) dx.
Solution: Here the idea is to complete the square in the denominator and then proceed with substitutions. Since ` x^2 + 6x + 13 = (x+3)^2 + 4` , begin by letting `v = x+3` , so `dv = dx` and we have
`int1/(x^2 + 6x + 13) dx = int 1/(v^2+4) dv`.

Now since `v^2 + 4 = 4 ((v/2)^2 +1)` we let `u = v/2`, so `2du = dv`, and we have

 `int 1/(v^2+4) dv = int 1/4  (1)/(u^2 +1) 2 du `
`= 1/2 text{arc}tan(u) + C `
`= 1/2 text{arc}tan((x+3)/(2)) + C`.


The next examples introduce the technique of partial fractions which is an important idea of algebra.
Before doing the integration we note simply that `2/(x - 3) - 1/(x + 2) = (x + 7)/(x^2 - x - 6)`.

This type of identity is called a partial fraction decomposition.



Example VII.F.4: Find  `int (x + 7)/(x^2 - x - 6) dx`.
Solution: From the algebraic identity just noted, we use linearity to obtain the result:
`int (x + 7)/(x^2 - x - 6) dx = int 2/(x - 3) - 1/(x + 2) dx = 2 ln|x - 3| - ln|x + 2|  + C`
Remark: Of course this problem was made easy by having the partial fraction decomposition before starting the integration.     


Example VII.F.5: Find ` int (x + 1)/(x^2 - 6x + 9) dx`.
Solution: First we factor the denominator, `x^2 - 6x + 9 = (x-3)^2`. Now we find another partial fraction decomposition,
`(x + 1)/(x^2 - 6x + 9) = 1/(x - 3) + 4/((x-3)^2) `
This gives us the result  `int(x + 1)/(x^2 - 6x + 9) dx = int 1/(x - 3) + 4/((x-3)^2) dx = ln |x - 3| - 4/(x - 3) + C`


By this time you may be asking , "How did he find those decompositions?" and "Can you always find a partial fraction decomposition for a rational function that will make the integration easy?"

To answer the second question first, it can be shown that any rational function has a partial fraction decomposition that will allow one to integrate the function with relative ease. The proof of this result is found in more advanced work in algebra and will not be given here. Perhaps more important to our purposes is the answer to the first question of how to find such decompositions. This also calls for an excursion into algebra, but one worth the effort at this time. 


VII.F.a Partial Fraction Decompositions-A Brief Sidetrip to Algebra

Example VII.F.6: Find a partial fraction decomposition for `(3x+1)/(x^2-1)`.
Solution: The method we use might be described as "wishful thinking" analysis. Imagine that we already have a partial faction decomposition. What will it look like? First factor the denominator, `x ^2-1 = (x+1)(x-1)`. Now proceed to try to find constants A and B so that `(3x+1)/(x^2 - 1) = A/(x+1) + B/(x-1)`.

Multiplying both sides of this equation by the denominator `x^2 - 1`, we obtain the equation

`3x + 1 = A(x - 1) + B(x + 1) =(A + B)x + B - A`.

We'll give two methods for finding the constants at this stage.

Method 1. Since these polynomials are equal, more wishful thinking suggests the coefficient of `x` and the constant term must also be equal. Thus we have two equations: `A + B = 3` from  the coefficient of `x` and `B - A = 1` from the constants.
Therefore adding these equations gives `2B = 4`, `B = 2`, and then we see that `A = 1`.

Method 2. Since these polynomials are equal, they give the same value for any choice of `x`.
Let `x = 1`. Then `3(1)+1 = A(1 - 1) + B(1 + 1) = 2B`.
So again we find that `4 = 2B` and `B = 2`.
Now let `x = 0`, use `B = 2`and we see that `3(0)+1 = A(0-1) + 2(0 + 1)`, so `1 = -A + 2` and `A = 1`.
 

Comment: Another choice that would be easier than `x = 0` is `x = -1`. Then we have

`3(-1) + 1 = A((-1) - 1) + B((-1) + 1)` or `-2 = -2A` .
So  we see that `A = 1` again.
______________________________________________________________________
Example VII.F.7: Find a partial fraction decompositon for `x/(x^3-1)`.
Solution: We follow the same kind of "wishful thinking" analysis. First factor the denominator, `x^3 - 1 =  (x - 1)(x^2 + x + 1)`.
We try to find constants A, B and C so that `x/(x^3 - 1) = A/(x-1) + (Bx + C)/(x^2 + x + 1)`.

Multiplying both sides of the equation by the denominator `x^3 - 1`, we obtain the equation

`x = A(x^2 + x + 1) + (Bx + C)(x - 1) = (A + B)x^2 + (A - B + C)x + A - C`.
<>Method 1. Equating the coefficients and constants of these polynomials, we see using some linear algebra that
`A + B        = 0`  (Eq. I)  [A = -B],
`A - B + C  = 1`  (Eq. II) and
`A       - C   = 0`  (Eq. III) [A = C] ,
so that by adding Eq. II and Eq. III we get
`2A - B       = 1`   (Eq. IV).
Now by combining Eq. I with Eq. IV we have
 `3A = 1`. Hence `A = C = 1/3`, and `B = -1/3`.

Method 2. Let `x = 1`. Thus `1 = A(1 + 1 + 1) + (B + C)(1 - 1)` and `A = 1/3`.
Let `x = 0`. Then `0 = 1/3(0 + 0 + 1) + (B . 0 + C)(0 - 1)`, and `C = 1/3`.
Finally let `x = -1`. Then `-1 = 1/3(1) + (B(-1) + 1/3)(-2)`, or `-2B = -2/3` so that `B = -1/3`.

Note: In this example we can combine these methods. From Method 1 we see that `A = C = -B`. Using `x=1` in Method 2 we find that  `A= 1/3` , hence `A = C = 1/3`, and `B = -1/3`. 



Why partial fraction decomposition of proper rational functions can be difficult. The previous two examples illustrated some of the complications that can occur in a partial fraction decompositon.

First, you need to factor the denominator of the proper rational function into a product of linear and quadratic terms. It is a fundamental theorem of algebra (usually proven in an advanced course in mathematics) that this is possible in theory. Note that even though the theory says such a factoring is possible, there is another side to the theory that says that there is no direct method for factoring a polynomial of degree five or greater. So there is a sizeable gap between the theory of factoring and its practice.

After factoring the denominator, you then write an expression involving numerous arbitrary constants as coefficients of simpler terms with denominators determined by the factoring. The actual terms are described below in Tables VII.F.i and VII.F.ii. Once this expression is written, you equate it with the original function and multiply by the denominator to give an equation of polynomials. You can now use one of the two methods illustrated above to solve for the constants in this equation.

Table VII.F.i
Linear Factor Terms for 
Partial Fraction Decompositon
Factor Terms  
 
`x-a` `1/(x-a)`


`(x-a)^2` `1/(x-a)`, `1/((x-a)^2`

.
.
.




`(x-a)^n` `1/(x-a)`, `1/((x-a)^2)`, ..., `1/((x-a)^n)`

 
Table VII.F.ii
Quadratic Factor Terms for 
Partial Fraction Decompositon
Factor
Terms
`(x-b)^2 + c^2`
`1/((x-b)^2 + c^2)` AND
`x/((x-b)^2 + c^2) `
`((x-b)^2 + c^2)^2`
`1/((x-b)^2 + c^2)` ,  `1/(((x-b)^2 + c^2)^2)` AND 
`x/((x-b)^2 + c^2)`,  `x/(((x-b)^2 + c^2)^2)`
:
:
:
:
:
:
`((x-b)^2 + c^2)^n`
`1/((x-b)^2 + c^2)`,  `1/(((x-b)^2 + c^2)^2)` , ..., `1/(((x-b)^2 + c^2)^n)` AND
`x/((x-b)^2 + c^2)` ,  `x/(((x-b)^2 + c^2)^2)` , ..., `x/(((x-b)^2 + c^2)^n)`

COMMENT: This technique will give a partial fraction decomposition for any proper rational function. The integration of a rational function can be reduced using this decomposition to the integration of each of the terms of the decomposition.


The technique discussed by the last comment is an effective but not too speedy way to integrate a rational function after "long division" and the denominator has been factored. The fact is that after all the sometimes tedious work  in finding the appropriate partial fraction decomposition for the function, you're still not done: you still need to proceed with care to integrate each term of the decomposition. This is not too distracting in examples similar to those already done, but when the denominator involves higher powers of quadratic expressions, the following method (which I first learned from Calculus of One Variable, a calculus textbook by Robert Seeley) avoids some of the frustration.

VII.F.b. A METHOD FOR INTEGRATING RATIONAL FUNCTIONS

(See Seeley, Calculus of One Variable, pgs.234-5)

STEP 1. Long Division. If you want to integrate `(P(x))/(Q(x))` where `P(x)` and `Q(x)` are polynomials,
write `(P(x))/(Q(x)) = T(x) + (R(x))/(Q(x))` where `T(x)` and `R(x)` are polynomials and the degree of `R(x)` is less than the degree of `Q(x)`. DO THIS BY USING LONG DIVISION OF POLYNOMIALS. This reduces the problem to integrating `(R(x))/(Q(x))` because `int T(x) dx` is easy. [See Ex.VII.F.1.]

STEP 2. Factor the denominator. This will be a product of linear terms and quadratic terms. Complete the squares of the quadratic (nonfactorable) terms. Thus you'll have

`Q(x)=a_0(x-a_1)^{r_1}...(x-a_m)^{r_m} [(x-b_1)^2+c_1^2]^{s_1}...[(x-b_n)^2+c_n^2]^{s_n}` .

[The factoring of polynomials in this fashion is a very important result of algebra usually referred to as one form of the "Fundamental Theorem of Algebra." It was first proven by Gauss in his doctoral dissertation, and is proven in several advanced courses in mathematics. ]

STEP 3.  Write the answer. Write the integral `int (R(x))/(Q(x)) dx` as a sum of terms, each term multiplied by an undetermined constant and arising from one of the factors of Q(x) according to the following rules:

(a) Each factor of the form `(x - a)^r` requires the terms:

`ln|x - a|, 1/(x - a),..., 1/((x-a)^{r-1})`

(b) Each factor of the form `[(x-b)^2+c^2]^s` requires the terms:

`text{arc}tan((x - b)/c),1/((x - b)^2 + c^2),1/(((x - b)^2 + c^2)^2),...,1/(((x - b)^2 + c^2)^{s-1})` AND
`ln[(x - b)^2+c^2],x/((x - b)^2 + c^2), x/(((x - b)^2 + c^2)^2) ,..., x/(((x - b)^2 + c^2)^{s-1})`

Table VII.F.i
Linear Factor Terms for 
Rational Function Integral Solution
Factor Terms  
 
`x - a` `ln|x - a|`


`(x - a)^2` `ln|x - a|`,  `1/(x - a)`

.
.
.




`(x - a)^r` `ln|x - a|`, `1/(x - a)`, ..., `1/((x-a)^{r-1})`

 
Table VII.F.ii
Quadratic Factor Terms for 
Rational Function Integral Solution
`(x-b)^2 + c^2`
`text{arc}tan((x - b)/c) ` AND
`ln[(x - b)^2+c^2]`
`((x-b)^2 + c^2)^2`
`text{arc}tan((x - b)/c),1/((x - b)^2 + c^2)` AND 
`ln[(x - b)^2+c^2], x/((x - b)^2 + c^2)`
:
:
:
:
:
:
`((x-b)^2 + c^2)^n`
`text{arc}tan((x - b)/c), 1/((x - b)^2 + c^2), 1/(((x - b)^2 + c^2)^2),..., 1/(((x - b)^2 + c^2)^{n-1})`AND
`ln[(x - b)^2+c^2], x/((x - b)^2 + c^2), x/(((x - b)^2 + c^2)^2) ,..., x/(((x - b)^2 + c^2)^{n-1})`

Remark: Step 3 is the most important since now `int (R(x))/(Q(x)) dx` is a linear combination of functions of the types listed in (a) and (b).

What you must remember is the types of terms required by the factors of `Q(x)`.
The number of terms in this combination is equal to the degree of `Q(x)`.

STEP 4. Differentiate.  Find the derivative of the the linear combination written in step 3 and place the answer over the common denominator, which is `Q(x)`! [Don't forget the chain rule!] The numerator is a polynomial of degree one less than the degree of `Q(x)`.

Don't spend any time with multiplying out the denominator!

STEP 5. Solve. Equate the numerator found in step 4 with `R(x)`. Now determine the constants introduced in step 3 by using one or both of the following methods.

(a) Multiply out the numerator with the undetermined coefficients, write it in standard polynomial form, and equate the coefficients of the corresponding powers of `x`. This will give a system of linear equations which can be solved by any of several techniques of linear algebra.

(b) Substitute some particular values for `x` in the numerator and `Q(x)` to obtain simpler expressions relating the undetermined coefficients.[See examples VII.F.... above.]


Remark: Factoring is not Easy. Seeley's method is still a fairly complicated and often tedious procedure for a polynomial of high degree. The most difficult task from the point of view of mathematics is the factoring of the denominator. Despite the Fundamental Theorem of Algebra's statement that each polynomial can be factored in theory as stated, there is another startling result in the theory of equations found independently by Evariste Galois (1811-1832) and Neils Abel (1802-1829). They showed that for a polynomial equation of degree greater than four there is no general formula that can express the roots of the polynomial equation in terms of the coefficients of the polynomial and the arithmetic operations of addition, subtraction, multiplication, division, and the finding n th roots of numbers. As a consequence of this result, though in theory we know that the denominator of the rational function can be factored as claimed, the factoring in practice may be very difficult since there is no general formula for the factors based on the coefficients and the arithmetic operations just mentioned.

Example VII.F.8: Find `int (x + 1)/((x^2 - 6x + 13)(x-2)^2) dx`.

Solution: We follow Seeley's method.
Step 1. Long Division. We notice that the integrand is a proper rational function so we may proceed to
Step 2. Factor the denominator. Completing the square of the quadratic factor we have

`x^2 - 6x + 13 = (x - 3)^2 + 2^2`,

so the denominator is `[(x - 3)^2 + 2^2] (x - 2)^2` .

Step 3. Write the answer. We can now say the integral is the following combination of functions determined by the factors of the denominator:

`A ln|x - 2| + B/(x - 2) + C text{arc}tan((x - 3)/2) + D ln|x^2 - 6x + 13| + K`
where K is the constant of integration.

Note that the denominator is a fourth degree polynomial and the previous combination involves exactly four summands with four constants to be determined.

Step 4. Differentiate. The derivative of the last expression is equal to the integrand [`(x + 1)/((x^2 - 6x + 13)(x-2)^2)`].

`A/(x-2) - B/((x-2)^2 ) + (2C)/( x^2 - 6x + 13) + (2(x-3) D)/(x^2 - 6x + 13)`.

Well this is certainly a complicated expression, but it does have the same common denominator as the integrand. After some further algebra we arrive at
Step 5. Solve.
We equate  the numerator of the integrand and the numerator of the last expression when placed over the common denominator and solve for the constants.

`x + 1 = A(x - 2)(x^2 - 6x + 13) - B(x^2 - 6x + 13) + 2C(x - 2)^2 + 2(x - 3)D(x - 2)^2` .

This is definitely one long mess!
Letting `x = 2` gives some help, so that `3 = -B ( 4 -12 + 13)` and thus `B = -3/5`.
Letting `x = 3`, 1,and 0 gives us three equations that assist in completing the algebraic part of the problem.

Let `x = 3` :    `4 = A(1)(4) + 3/5 (4) + 2C(1)` ; so `8/5 = 4 A + 2 C`.

Let `x = 1` :    `2 = A(-1)(8) + 3/5 (8) + 2C + 2(-2)D(1)`; so ` -14/5 = -8A + 2 C - 4 D`.

Let `x = 0` :    `1 = A(-2)(13) + 3/5 (13) + 2C(4) + (2)(-3)D(4)`; so `-34/5 = -26 A + 8 C -24 D`.

One can check that the solution to these equations is given by `A = 11/25, C = -2/25`  and `D = -11/50`.
Thus

`int (x + 1)/((x^2 - 6x + 13)(x-2)^2) dx`
`= 11/25 ln|x - 2| - 3/(5(x - 2)) - 2/25 text{arc}tan((x-3)/2) - 11/50 ln|x^2 - 6x + 13| + K`.

Exercises VII.F

Find the following integrals:

1. `int (x + 2)/(16 - x^2 )dx`

2. `int (3 x -5)/(1 + 2x + x^2 ) dx`

3. `int 1/( x ( 1 +x)^2)dx`

4. `int x/(1 - x^4 )dx`

5. `int (x + 1)/( 16 + 16x^2 )dx`

6. `int (3x + 1)/( 2 - 2x + x^2 )dx`

7. `int (x^2 + x + 1)/(4 - x^2 )dx`

8. `int 1/(x ( 1 - x^2)) dx`

9. `int (x^4)/(1 + x^3 )dx

10. `int (x^3)/(2x - x^2 )dx

Here are some more:

11. `int (x + 2)/(8 - x^3) dx`

12. `int (3 x -5)/( (1 + 2x + x^2)(1+x)) dx`

13.  `int 1/( x ( 1 + x^2)) dx`

14. `int x/(1 - x^3 )dx`

15. `int (3x + 1)/((2 - 2x + x^2)(1 - x))dx`

16. `int (x + 1)/( 8 + x^3 )dx`

17. `int (x^2 + x + 1)/(4 + x^2 )dx`

18. `int 1/( (x + 1) ( 1 - x^2) )dx`

19. `int (x^2)/(1-x^3)dx`

20. `int (x^3)/(2x - x^3) dx`