Partial Fraction Decomposition with Mathematica

Copyright © 2001 by James F. Hurley, University of Connecticut, Department of Mathematics, Unit 3009, Storrs CT 06269-3009.  All rights reserved.

This Mathematica notebook discusses the method of integration by partial-fraction decomposition. The examples it considers are simple enough to do by hand. Their purpose is to illustrate use of a computer-algebra system to carry out calculations that by hand can become tedious, time-consuming and prone to error. Once you master the basics of partial-fraction decomposition and practice enough to work problems by hand in 5 minutes or so, you can use this notebook to check your work, or to evaluate more complicated integrals. Don't make the mistake of relying on Mathematica entirely, because it won't be available for quiz or exam questions! (And, as you'll see, it's not perfect either!)

    Note: To see the result of a command, position the cursor (I-beam) to the right of the command and hit Enter on the numeric keypad, or type Shift-Return or Command (ýÿ)-Return on the main part of the keyboard, or select the command and choose Evaluate Cells from the Evaluation submenu of the Kernel menu.

1. The Apart Command. Consider the problem of integrating the rational function f(x) = p(x)/q(x), where p(x) = [Graphics:Images/ParFrac_gr_1.gif] + 2[Graphics:Images/ParFrac_gr_2.gif]-- x + 1 and q(x) = [Graphics:Images/ParFrac_gr_3.gif] -- x -- 6. Defining a function in Mathematica requires the special colon/equal symbol := as well as an underscore (_) subscript after the function's independent variable. (Failure to observe this rule can cause puzzling problems!) For example, the proper definition of the function f above is

f[x_]:=(x^3 + 2 x^2 - x + 1)/(x^2 - x - 6)

    Since the degree of the numerator p(x) of f(x) is not less than the degree of its denominator q(x), the function f(x) is not in proper form to decompose into a sum of partial fractions. Before proceeding by hand, you would have to divide the numerator by the denominator to obtain the quotient polynomial s(x), and then decompose the function r(x)/q(x), where r(x) is the remainder polynomial from the division process, for which deg r(x) <  deg q(x). However, Mathematica will do that division in the background and provide a partial-fraction decomposition of f(x) in one step, by invoking its Apart command. To illustrate that, just execute the following command.

Apart[f[x]]
[Graphics:Images/ParFrac_gr_4.gif]

You don't even have to define the function f(x), as you can see by executing the following command.

Apart[(x^3 + 2*x^2 - x + 1)/(x^2 - x - 6)]
[Graphics:Images/ParFrac_gr_5.gif]

    You can check the decomposition by asking Mathematica to add the partial fractions. Symmetric to Apart, the command to so is Together.

Together[x + 3 + 43/(5*(x - 3)) - 3/(5*(x + 2))] 
[Graphics:Images/ParFrac_gr_6.gif]

You can check that the decomposition is exactly what you would get by hand by first dividing p(x) by q(x) to get s(x) and r(x), and then using Apart on r(x)/q(x). For that, use Mathematica's built-in commands for finding the quotient and remainder when p(x) is divided by q(x).

[Graphics:Images/ParFrac_gr_7.gif]
[Graphics:Images/ParFrac_gr_8.gif]
[Graphics:Images/ParFrac_gr_9.gif]
[Graphics:Images/ParFrac_gr_10.gif]
[Graphics:Images/ParFrac_gr_11.gif]
[Graphics:Images/ParFrac_gr_12.gif]

Note that s(x) = x + 3 added to the last expression is exactly what Apart gave when applied to f(x). Is Mathematica then foolproof? It would appear so, at least with regard to partial-fraction decomposition! Its partioal-decomposition makes it easy to integrate the given rational function f(x):

                              f(x) dx = (3 + x) dx + [Graphics:Images/ParFrac_gr_13.gif]dx
                                         = 3x + [Graphics:Images/ParFrac_gr_14.gif] + [Graphics:Images/ParFrac_gr_15.gif] ln |x -- 3| -- [Graphics:Images/ParFrac_gr_16.gif]ln |x + 2|  + C
                                                                                          
    
What does Mathematica's Integrate command give directly (with no indication of what calculus it employs to produce the printed answer)? Try it!

Integrate[f[x], x]
[Graphics:Images/ParFrac_gr_17.gif]

    Some mathematicians claim that Mathematica could earn a B in a standard second-semester calculus course. It certainly doesn't get a perfect score on this problem: the answer has no constant of integration and no absolute-value signs around the variables in the ln function (which, like most computer-related products, Mathematica denotes by Log). Each of those omissions could lose one point on a 10-point question that asked for f(x) dx, so indeed Mathematica looks like no better than a B student on this! The moral: do enough partial-fraction decomposition by hand to be able to solve problems like this in 5 minutes without technological aids! Work most or all the homework set by hand, and use Mathematica to check your answers.

2. Quadratic Denominator Factors. Consider next an example in which the denominator function has an irreducible quadratic factor, [Graphics:Images/ParFrac_gr_18.gif]dx. The denominator factors as ([Graphics:Images/ParFrac_gr_19.gif]-- 4)([Graphics:Images/ParFrac_gr_20.gif]+ 4) = (x -- 2)(x + 2)([Graphics:Images/ParFrac_gr_21.gif] + 4), where the factor [Graphics:Images/ParFrac_gr_22.gif]+ 4 is irreducible (that is, is not the product of any linear factors) over the system R of real numbers. Mathematica gives this factorization easily. Try

Factor[x^4 - 16]
[Graphics:Images/ParFrac_gr_23.gif]
The Apart command, however doesn't need this information, since it factors the polynomials in the background and then decomposes accordingly. It is enough to execute the following command directly.
Apart[x^2/(x^4 - 16)]
[Graphics:Images/ParFrac_gr_24.gif]

Basic antidifferentiation formulas then give the integral with minimal additional work:
          
         [Graphics:Images/ParFrac_gr_25.gif]dx = [Graphics:Images/ParFrac_gr_26.gif][Graphics:Images/ParFrac_gr_27.gif] -- [Graphics:Images/ParFrac_gr_28.gif][Graphics:Images/ParFrac_gr_29.gif] + [Graphics:Images/ParFrac_gr_30.gif] [Graphics:Images/ParFrac_gr_31.gif]
                         = [Graphics:Images/ParFrac_gr_32.gif] ln |x -- 2|  -- [Graphics:Images/ParFrac_gr_33.gif] ln |x + 2| + [Graphics:Images/ParFrac_gr_34.gif][Graphics:Images/ParFrac_gr_35.gif] arctan([Graphics:Images/ParFrac_gr_36.gif]) + C
                                 =
[Graphics:Images/ParFrac_gr_37.gif] ln |[Graphics:Images/ParFrac_gr_38.gif]| + [Graphics:Images/ParFrac_gr_39.gif] arctan([Graphics:Images/ParFrac_gr_40.gif]) + C.

    
This is considerably less work than a hand-based solution would involve. For comparison, try the following to see the output of Mathematica's Integrate command for the given integrand.

Integrate[x^2/(x^4 - 16), x]
[Graphics:Images/ParFrac_gr_41.gif]

At first glance, this is not even B work: besides the missing constant, the arctan term appears to be wrong. However, as you can verify for yourself, the answer actually is consistent with the result of the hand calculation. The only errors here are the same ones Mathematica made before: no constant of integration, and missing absolute-value bars in the Log functions. Another 8 points out of 10, probably!

    It is a bit dangerous to rely heavily on the Integrate command, because you have no way to determine what method Mathematica uses to find an antiderivative. As the last example illustrates, it may well give a correct formula that on the surface looks quite different from an equally correct formula you (or the answer book) may derive by hand using a method from the course. So even as a checker, it is wise to treat Mathematica not as fountainhead of knowledge, but rather as a fellow student -- one with a pretty limited personality at that, and little potential to earn a grade better than B!


Converted by Mathematica      March 2, 2001