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) = + 2-- x + 1 and q(x) = -- 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.
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)]
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))]
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).
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 + ∫ dx
= 3x + + ln |x -- 3| -- 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!
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, ∫dx. The denominator factors as (-- 4)(+ 4) = (x -- 2)(x + 2)( + 4), where the factor + 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]
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)]
Basic antidifferentiation formulas then give the integral with minimal additional work:
∫dx = ∫ -- ∫ + ∫
= ln |x -- 2| -- ln |x + 2| + arctan() + C
= ln || + arctan() + 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]
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!