CoCalc Public Files08 - Partial Fractions Assignment / Partial Fractions Notes.sagews
Author: Aaron Tresham
Views : 37
Compute Environment: Ubuntu 20.04 (Default)
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is

### Prerequisites:

• 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:

$\frac{1}{x+1}+\frac{-1}{x+3}=\frac{2}{(x+3)(x+1)}$

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)
f(x).partial_fraction()
show(_)

-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.

f(x)=x/(x^2+4*x+3)
integral(f(x),x)
show(_)

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:

f(x).partial_fraction()
show(_)

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

So $\frac{x}{x^2+4x+3}=\frac{3/2}{x+3}+\frac{-1/2}{x+1}$

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 $R(x)=\frac{P(x)}{(x-r_1)(x-r_2)\cdots(x-r_n)}$

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:

$R(x)=\frac{a_1}{x-r_1}+\frac{a_2}{x-r_2}+\cdots+\frac{a_n}{x-r_n}$

Then $\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$

$=a_1\ln(|x-r_1|)+a_2\ln(|x-r_2|)+\cdots+a_n\ln(|x-r_n|)+C$

## 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.

f(x)=(2*x^2+4*x+3)/((x+3)*(x+2)*(x-1))
#Make sure you have parentheses around the top and the entire bottom. You must put * between factors.
integral(f(x),x)
show(_)

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)$
f(x).partial_fraction()
show(_)

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)

So $\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$

$=\frac{9}{4}\ln(|x+3|)-\ln(|x+2|)+\frac{3}{4}\ln(|x-1|)+C$

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 $R(x)=\frac{P(x)}{(x-r)^n}$

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

Then there exist constants $a_i$ such that $R(x)=\frac{a_1}{x-r}+\frac{a_2}{(x-r)^2}+\cdots+\frac{a_n}{(x-r)^n}$

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$

$=a_1\ln(|x-r|)+a_2\frac{1}{-1}\frac{1}{x-r}+a_3\frac{1}{-2}\frac{1}{(x-r)^2}+\cdots+a_n\frac{1}{-n+1}\frac{1}{(x-r)^{n-1}}+C$

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$.

f(x)=(x^2-2)/(x-1)^3
integral(f(x),x)
show(_)

-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)$
f(x).partial_fraction()
show(_)

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.
integral(f(x),x)
show(_)

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)$
f(x).partial_fraction()
show(_)

-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$.

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

$R(x)=\frac{P(x)}{(a_1x^2+b_1x+c_1)(a_2x^2+b_2x+c_2)\cdots(a_nx^2+b_nx+c_n)}$

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

$R(x)=\frac{d_1x+e_1}{a_1x^2+b_1x+c_1}+\frac{d_2x+e_2}{a_2x^2+b_2x+c_2}+\cdots+\frac{d_nx+e_n}{a_nx^2+b_nx+c_n}$

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.
integral(f(x),x)
show(_)

-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.

f(x).partial_fraction()
show(_)

(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)
show(_)

-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)
show(_)

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 $\int\frac{x}{x^2+1}\,dx=\int\frac{1}{2}\cdot\frac{1}{u}\,du=\frac{1}{2}\ln(|u|)+C=\frac{1}{2}\ln(x^2+1)+C$

(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:

$\frac{2x-1}{x^2+x+2}=\frac{2x+1}{x^2+x+2}+\frac{-2}{x^2+x+2}$

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.

$\frac{-2}{x^2+x+2}=\frac{-2}{\left(x+\frac{1}{2}\right)^2+\frac{7}{4}}$

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

$\frac{-2}{\left(x+\frac{1}{2}\right)^2+\frac{7}{4}}=\frac{-2}{\frac{7}{4}\left[\left(\frac{2}{\sqrt{7}}x+\frac{1}{\sqrt{7}}\right)^2+1\right]}=\frac{-8}{7}\cdot\frac{1}{\left(\frac{2}{\sqrt{7}}x+\frac{1}{\sqrt{7}}\right)^2+1}$

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

$\int\frac{-8}{7}\cdot\frac{1}{\left(\frac{2}{\sqrt{7}}x+\frac{1}{\sqrt{7}}\right)^2+1}\,dx=\frac{-4\sqrt{7}}{7}\int\frac{1}{u^2+1}\,du=\frac{-4\sqrt{7}}{7}\arctan(u)+C=\frac{-4\sqrt{7}}{7}\arctan\left(\frac{2}{\sqrt{7}}x+\frac{1}{\sqrt{7}}\right)+C$

Aren't you glad to have Sage?

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

$R(x)=\frac{P(x)}{(ax^2+bx+c)^n}$

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

$R(x)=\frac{d_1x+e_1}{ax^2+bx+c}+\frac{d_2x+e_2}{(ax^2+bx+c)^2}+\cdots+\frac{d_nx+e_n}{(ax^2+bx+c)^n}$

## Example 7

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

f(x)=(x^3+2)/(x^2+1)^2
integral(f(x),x)
show(_)

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)$
f(x).partial_fraction()
show(_)

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)
show(_)

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

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 $R(x)=S(x)+\frac{T(x)}{Q(x)}$

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 $\frac{x^3+x+1}{x-2}=x^2+2x+5+\frac{11}{x-2}$

Thus, $\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.

f(x)=(x^3+x+1)/(x-2)
f(x).partial_fraction()
show(_)

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)