Shared09 - Partial Fractions Assignment / Partial Fractions Notes.sagewsOpen in CoCalc
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is Creative Commons License
licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


  • Intro to Sage
  • Symbolic Integration

Partial Fractions

Partial fraction decomposition is a tool to help us integrate rational functions (quotients of polynomials). It allows us to "decompose" a complicated rational function into a sum of simpler rational functions.

It is the reverse of fraction addition. For example, consider this addition:


Partial fraction decomposition undoes the addition.

So if you wanted to find the antiderivative of \displaystyle\frac{2}{(x+3)(x+1)} , you could find the antiderivatives of \displaystyle\frac{1}{x+1} and \displaystyle\frac{-1}{x+3} and add them together.

Of course, in terms of practice, it is silly to use the computer to do partial fraction decomposition in order to integrate, since the computer can already integrate the original rational function. So the goal of this lab is to explore the different kinds of decompositions and the kind of antiderivatives you get out of the process.

Example 1

Here is an example of computing a partial fraction decomposition in Sage:

f(x)=2/(x^2 + 4*x + 3)
-1/(x + 3) + 1/(x + 1)
\displaystyle -\frac{1}{x + 3} + \frac{1}{x + 1}

Example 2

Find the antiderivative of \displaystyle f(x)=\frac{x}{x^2+4x+3} .

First, we'll integrate with Sage, then we'll find the partial fraction decomposition and integrate term by term.

3/2*log(x + 3) - 1/2*log(x + 1)
\displaystyle \frac{3}{2} \, \log\left(x + 3\right) - \frac{1}{2} \, \log\left(x + 1\right)

Note: We would normally write this as follows:

\int\frac{x}{x^2+4x+3}\, dx=\frac{3}{2}\ln(|x+3|)-\frac{1}{2}\ln(|x+1|)+C

(notice the absolute values and the +C ).

Now let's try partial fractions:

3/2/(x + 3) - 1/2/(x + 1)
\displaystyle \frac{3}{2 \, {\left(x + 3\right)}} - \frac{1}{2 \, {\left(x + 1\right)}}



This means

\int\frac{x}{x^2+4x+3}\, dx=\int\frac{3/2}{x+3}+\frac{-1/2}{x+1}\, dx=\frac{3}{2}\int\frac{1}{x+3}\, dx-\frac{1}{2}\int\frac{1}{x+1}\, dx

integral(3/2/(x + 3),x)
integral(- 1/2/(x + 1),x)
3/2*log(x + 3) -1/2*log(x + 1)

Non-repeated Linear Factors

In general, a rational function whose denominator has distinct linear factors will decompose similar to the last example.

Suppose R(x) is a rational function which may be written as


where P(x) is a polynomial of degree less than n and all the r_i are distinct (note: n is the degree of the denominator).

Then there exists constants a_i (i.e., real numbers) such that:



\int R(x)\, dx=a_1\int\frac{1}{x-r_1}\, dx+a_2\int\frac{1}{x-r_2}\, dx+\cdots+a_n\int\frac{1}{x-r_n}\, dx


Example 3

Find \displaystyle\int\frac{2x^2+4x+3}{(x+3)(x+2)(x-1)}\, dx.

Again, we'll use Sage to compute the integral directly, and then we'll compare the partial fraction approach.

#Make sure you have parentheses around the top and the entire bottom. You must put * between factors.
9/4*log(x + 3) - log(x + 2) + 3/4*log(x - 1)
\displaystyle \frac{9}{4} \, \log\left(x + 3\right) - \log\left(x + 2\right) + \frac{3}{4} \, \log\left(x - 1\right)
9/4/(x + 3) - 1/(x + 2) + 3/4/(x - 1)
\displaystyle \frac{9}{4 \, {\left(x + 3\right)}} - \frac{1}{x + 2} + \frac{3}{4 \, {\left(x - 1\right)}}
integral(9/4/(x + 3),x)
integral(- 1/(x + 2),x)
integral(3/4/(x - 1),x)
9/4*log(x + 3) -log(x + 2) 3/4*log(x - 1)


\int\frac{2x^2+4x+3}{x^3+4x^2+x-6}\,dx=\frac{9}{4}\int\frac{1}{x+3}\, dx+(-1)\int\frac{1}{x+2}\, dx+\frac{3}{4}\int\frac{1}{x-1}\,dx


Note: To perform the partial fraction decomposition by hand, you have to first factor the denominator (another example where finding roots of polynomials is important), and then you set up a system of equations to solve for the constants (the a_i ). I'll leave the details to your lecture professor. It's a lot of work, but it's the only way to deal with rational functions by hand.

Repeated Linear Factors

Let's start with a rational function with only one root with multiplicity greater than 1.

Suppose a rational function R(x) may be written


where P(x) is a polynomial of degree less than n (the degree of the denominator).

Then there exist constants a_i such that


Integrating each of these terms is fairly simple.

\int R(x)\, dx=a_1\int\frac{1}{x-r}\,dx+a_2\int\frac{1}{(x-r)^2}\,dx+\cdots+a_n\int\frac{1}{(x-r)^n}\,dx


Recall, \displaystyle\int\frac{1}{x}\,dx=\ln(|x|)+C , and for n\ne 1 , \displaystyle\int\frac{1}{x^n}\,dx=\int x^{-n}\,dx=\frac{1}{-n+1}x^{-n+1}+C=\frac{1}{-n+1}\frac{1}{x^{n-1}}+C .

Example 4

Find \displaystyle\int\frac{x^2-2}{(x-1)^3}\,dx .

-1/2*(4*x - 5)/(x^2 - 2*x + 1) + log(x - 1)
\displaystyle -\frac{4 \, x - 5}{2 \, {\left(x^{2} - 2 \, x + 1\right)}} + \log\left(x - 1\right)
1/(x - 1) + 2/(x - 1)^2 - 1/(x - 1)^3
\displaystyle \frac{1}{x - 1} + \frac{2}{{\left(x - 1\right)}^{2}} - \frac{1}{{\left(x - 1\right)}^{3}}
show(integral(1/(x - 1),x))
show(integral(2/(x - 1)^2,x))
show(integral(-1/(x - 1)^3,x))
\displaystyle \log\left(x - 1\right)
\displaystyle -\frac{2}{x - 1}
\displaystyle \frac{1}{2 \, {\left(x - 1\right)}^{2}}

Our answers look different, but they are the same. In the first integral, Sage has combined the rational pieces into one. In the partial fraction approach we can see the two rational pieces separately. In other words, \displaystyle-\frac{1}{2}\cdot\frac{4x-5}{x^2-2x+1}=\frac{-2}{x-1}+\frac{1/2}{(x-1)^2}

Here's an example with more than one repeated linear factor.

Example 5

Find \displaystyle\int\frac{2x-1}{(x+2)^2(x-3)^4} .

f(x)=(2*x-1)/((x+2)^2*(x-3)^4) #Careful with parentheses and multiplication.
1/375*(6*x^3 - 39*x^2 + 47*x - 77)/(x^4 - 7*x^3 + 9*x^2 + 27*x - 54) - 2/625*log(x + 2) + 2/625*log(x - 3)
\displaystyle \frac{6 \, x^{3} - 39 \, x^{2} + 47 \, x - 77}{375 \, {\left(x^{4} - 7 \, x^{3} + 9 \, x^{2} + 27 \, x - 54\right)}} - \frac{2}{625} \, \log\left(x + 2\right) + \frac{2}{625} \, \log\left(x - 3\right)
-2/625/(x + 2) + 2/625/(x - 3) - 1/125/(x + 2)^2 - 1/125/(x - 3)^2 + 1/5/(x - 3)^4
\displaystyle -\frac{2}{625 \, {\left(x + 2\right)}} + \frac{2}{625 \, {\left(x - 3\right)}} - \frac{1}{125 \, {\left(x + 2\right)}^{2}} - \frac{1}{125 \, {\left(x - 3\right)}^{2}} + \frac{1}{5 \, {\left(x - 3\right)}^{4}}
show(integral(-2/625/(x + 2),x))
show(integral(2/625/(x - 3),x))
show(integral(-1/125/(x + 2)^2,x))
show(integral(-1/125/(x - 3)^2,x))
show(integral(1/5/(x - 3)^4,x))
\displaystyle -\frac{2}{625} \, \log\left(x + 2\right)
\displaystyle \frac{2}{625} \, \log\left(x - 3\right)
\displaystyle \frac{1}{125 \, {\left(x + 2\right)}}
\displaystyle \frac{1}{125 \, {\left(x - 3\right)}}
\displaystyle -\frac{1}{15 \, {\left(x - 3\right)}^{3}}

So our integral is \displaystyle-\frac{2}{625}\ln(|x+2|)+\frac{2}{625}\ln(|x-3|)+\frac{1}{125}\cdot\frac{1}{x+2}+\frac{1}{125}\cdot\frac{1}{x-3}-\frac{1}{15}\frac{1}{(x-3)^3}+C .

Non-repeated Irreducible Quadratics

We know that some polyomials do not have real roots. Such polynomials cannot be factored into (real) linear factors. However, any polynomial can be factored into linear factors and irreducible quadratic factors (in this context, irreducible means these quadratic functions have no real roots - you may recall that such functions have two complex roots, which are complex conjugates).

We now consider partial fraction decomposition for rational functions that have irreducible quadratic factors in the denominator.

Suppose R(x) is a rational function which may be written


where all the quadratics factors in the denominator are distinct, and the degree of P(x) is less than 2n (the degree of the denominator).

Then there exist constants d_i and e_i such that


Integrating this is usually a pain. If you're lucky, some of these terms may be fairly simple substitution problems (when the numerator is a constant multiple of the derivative of the denominator). When you integrate, your answer involves a natural logarithm (ln).

If you're not so lucky, then you have to do some algebra, including completing the square. After integrating, the result may involve a natural logarithm and/or an inverse tangent (arctan).

If that sounds bad, that's because it is!

Example 6

Find \displaystyle\int\frac{3x^3+4x-1}{(x^2+1)(x^2+x+2)} .

Note: the quadratics in the denominator are irreducible.

f(x)=(3*x^3+4*x-1)/((x^2+1)*(x^2+x+2))  #Don't forget the () around the bottom and the * between factors.
-4/7*sqrt(7)*arctan(1/7*sqrt(7)*(2*x + 1)) + log(x^2 + x + 2) + 1/2*log(x^2 + 1)
\displaystyle -\frac{4}{7} \, \sqrt{7} \arctan\left(\frac{1}{7} \, \sqrt{7} {\left(2 \, x + 1\right)}\right) + \log\left(x^{2} + x + 2\right) + \frac{1}{2} \, \log\left(x^{2} + 1\right)

Our answer involves three terms: two natural logs and one arctan. Let's use partial fractions to see where these come from.

(2*x - 1)/(x^2 + x + 2) + x/(x^2 + 1)
\displaystyle \frac{2 \, x - 1}{x^{2} + x + 2} + \frac{x}{x^{2} + 1}

Integrating the first term gives the arctan and one log:

integral((2*x - 1)/(x^2 + x + 2),x)
-4/7*sqrt(7)*arctan(1/7*sqrt(7)*(2*x + 1)) + log(x^2 + x + 2)
\displaystyle -\frac{4}{7} \, \sqrt{7} \arctan\left(\frac{1}{7} \, \sqrt{7} {\left(2 \, x + 1\right)}\right) + \log\left(x^{2} + x + 2\right)

Integrating the second terms gives the other log:

integral(x/(x^2 + 1),x)
1/2*log(x^2 + 1)
\displaystyle \frac{1}{2} \, \log\left(x^{2} + 1\right)

The last piece is a simple substitution. Let u=x^2+1 . Then du=2x\, dx , so


(Note: x^2+1 is positive, so you don't need the absolute value.)

The first piece is more complicated (as you can see by the result).

Notice, if you tried to substitute u=x^2+x+2 , then you get du=2x+1\, dx , which is not what you have in the numerator. But we can force it into the numerator and then adjust by adding another term:


When you integrate the first term, you get \ln(x^2+x+2) .

The second term is where the arctan comes from, but the algebra is messy. First, you complete the square in the denominator.


Now you have to factor 7/4 out of the denominator.


Now substitute u=\frac{2}{\sqrt{7}}x+\frac{1}{\sqrt{7}} to get


Aren't you glad to have Sage?

Repeated Irreducible Quadratics

If the irreducible quadratic factors are repeated, you get something similar to what happened with the repeated linear factors.

Suppose R(x) is a rational function which may be written


where the quadratic is irreducible, and the degree of P(x) is less than 2n (the degree of the denominator).

Then there exist constants d_i and e_i such that


Example 7

Find \displaystyle\int\frac{x^3+2}{(x^2+1)^2} .

1/2*(2*x + 1)/(x^2 + 1) + arctan(x) + 1/2*log(x^2 + 1)
\displaystyle \frac{2 \, x + 1}{2 \, {\left(x^{2} + 1\right)}} + \arctan\left(x\right) + \frac{1}{2} \, \log\left(x^{2} + 1\right)
x/(x^2 + 1) - (x - 2)/(x^2 + 1)^2
\displaystyle \frac{x}{x^{2} + 1} - \frac{x - 2}{{\left(x^{2} + 1\right)}^{2}}
integral(x/(x^2 + 1),x)
1/2*log(x^2 + 1)
\displaystyle \frac{1}{2} \, \log\left(x^{2} + 1\right)
integral(-(x - 2)/(x^2 + 1)^2,x)
1/2*(2*x + 1)/(x^2 + 1) + arctan(x)
\displaystyle \frac{2 \, x + 1}{2 \, {\left(x^{2} + 1\right)}} + \arctan\left(x\right)

This last integral can be computed using trig substitution. I'll spare you the gory details.

What if the degree of the denominator is not greater than the degree of the numerator?

We have only considered examples where the degree of the numerator is less than the degree of the denominator. If this is not the case, then you must first use long division of polynomials to rewrite your rational function as a polynomial plus a new rational function for which the degree of the numerator is smaller.

In general, if R(x)=\frac{P(x)}{Q(x)} and the degree of P \ge degree of Q , then there exist polynomials S and T , with degree of T < degree of Q , such that


Integrating S(x) is easy (it's a polynomial), and integrating \frac{T(x)}{Q(x)} is accomplished as above.

Example 8

Find \displaystyle\int\frac{x^3+x+1}{x-2}\,dx .

First, we divide to find that



\int\frac{x^3+x+1}{x-2}\,dx=\int x^2+2x+5+\frac{11}{x-2}\,dx=\frac{1}{3}x^3+x^2+5x+11\ln(|x-2|)+C

There is a command in Sage to find the quotient and remainder from polynomial long division, but it's somewhat cumbersome to use. Fortunately, we don't have to worry about this, since the partial_fraction command will deal with this situation with no problems.

x^2 + 2*x + 11/(x - 2) + 5
\displaystyle x^{2} + 2 \, x + \frac{11}{x - 2} + 5
integral(x^2 + 2*x + 5,x)
integral(11/(x - 2),x)
1/3*x^3 + x^2 + 5*x 11*log(x - 2)