CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/142-Labs/Lab 04 - Integration of Rational Functions by Partial Fractions.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 04 - Integration of Rational Functions by Partial Fractions

Overview

In this lab, we will explore writing a rational function as a sum of simpler rational functions which can be easily integrated.

Important SageMath Commands Introduced in this Lab

ParseError: KaTeX parse error: Undefined control sequence: \hfill at position 32: …|l|l|} \hline \̲h̲f̲i̲l̲l̲ ̲\textbf{Command…
Section 8.5

Example 1

We will use SageMath to verify our partial fraction decomposition and our integration of the rational function f(x)=2(x+1)(x1).f(x) = \dfrac{2}{(x+1)(x-1)}. The general form of the partial fraction decomposition of f(x)f(x) is 2(x+1)(x1)=Ax+1+Bx1.\dfrac{2}{(x+1)(x-1)} = \dfrac{A}{x+1} + \dfrac{B}{x-1}. In order to solve for AA and BB by hand, we would clear the denominators by multiplying both sides by the denominator original denominator. This results in the equation 2=A(x1)+B(x+1)=(A+B)x+(A+B).2 = A(x-1) + B(x+1) = (A + B)x + (-A + B). Setting like terms equal, we obtain the system of linear equations {A+B=0A+B=2\left \{ \begin{array}{rcl} A + B & = & 0 \\ -A + B & = & 2 \end{array} \right . In the previous lab, we used the solve\textbf{solve} command to solve a single equation. This command will also allow us to solve a system of equations as well.

A,B = var('A','B') ## We first make A and B variables eq1 = A + B == 0 ## The first equation in the system eq2 = -A + B == 2 ## The second equation in the system solve([eq1, eq2], [A, B])

Therefore, we have that the partial fraction decomposition of our rational function is 2(x+1)(x1)=1x+1+1x1.\dfrac{2}{(x+1)(x-1)} = -\dfrac{1}{x+1} + \dfrac{1}{x-1}.

We can use the command ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 17: …textbf{.partial_̲fraction()} to check our partial fraction decomposition of f(x)f(x).

def f(x): return 2/((x+1)*(x-1)) show(f(x).partial_fraction())

Therefore, we have that 2(x+1)(x1) dx=1x+1+1x1 dx=lnx+1+lnx1+C.\int \dfrac{2}{(x+1)(x-1)} \ dx = \int -\dfrac{1}{x+1} + \dfrac{1}{x-1} \ dx = -\ln|x+1| + \ln|x-1| + C. We can use SageMath to check that our answer is correct by using the integrate\textbf{integrate} command. Remember that SageMath uses log(x)\textbf{log(x)} in place of ln|x|\textbf{ln|x|} and does not include +C+ C with antiderivatives.

show(integrate(f(x),x))

Example 2

Again, we will use SageMath to help determine the partial fraction decomposition and the antiderivative of the function f(x)=6x27xx32x2+x2f(x) = \dfrac{6x^2 - 7x}{x^3 - 2x^2 + x - 2}. The first thing we need to do is factor the denominator of f(x)f(x). Let denom(x)=x32x2+x2denom(x) = x^3 - 2x^2 + x - 2 be the denominator of f(x)f(x). Recall that (xa)(x-a) is a factor of denom(x)denom(x) if and only if denom(a)=0denom(a) = 0. Therefore, in order to factor the cubic denom(x)denom(x), we look for numbers aa such that denom(a)=0denom(a) = 0. Note that denom(a)=0denom(a) = 0 if and only if x=ax=a is an xx-intercept of denom(x)denom(x). Therefore, we use SageMath to plot denom(x)denom(x) and determine any xx-intercepts.

def denom(x): return x^3 - 2*x^2 + x - 2 plot(denom(x),xmin = -10, xmax = 10)

Using the domain [10,10][-10, 10] we see that denom(x)denom(x) does have an xx-intercept. However, we can't see exactly what it is since graph is too zoomed out. We can zoom in by choosing a smaller domain.

plot(denom(x), xmin=-3, xmax=3)

Therefore, we see that x=2x=2 is an xx-intercept of denom(x)denom(x). It follows that (x2)(x-2) is a factor of denom(x)denom(x). Thus, we know that denom(x)=(x2)denom2(x)denom(x) = (x-2)denom_2(x) where denom2(x)denom_2(x) is a polynomial. We can find denom2(x)denom_2(x) exactly by dividing denom(x)denom(x) by (x2).(x-2). In order to have SageMath divide the polynomials, we use the ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{.full_̲simplify()} command.

denom2(x) = denom(x) / (x-2) denom2(x).full_simplify()

Therefore, denom(x)denom(x) factors as (x2)(x2+1)(x-2)(x^2+1). Note that x2+1x^2 + 1 is an irreducible quadratic. Thus, the factorization of the denominator of f(x)f(x) is (x2)(x2+1)(x-2)(x^2+1). It follows that f(x)=6x27x(x2)(x2+1)f(x) = \dfrac{6x^2 - 7x}{(x-2)(x^2+1)}. Now that we have factored the denominator of f(x)f(x), we can use partial fraction decomposition to write f(x)f(x) as the sum of simpler fractions. Recall that the general form of f(x)f(x) into partial fractions is 6x27x(x2)(x2+1)=Ax2+Bx+Cx2+1.\dfrac{6x^2 - 7x}{(x-2)(x^2+1)} = \dfrac{A}{x-2} + \dfrac{Bx + C}{x^2 + 1}. Multiplying both sides of the equation by (x2)(x2+1)(x-2)(x^2 + 1) gives the equation 6x27x=A(x2+1)+(Bx+C)(x2)=(A+B)x2+(C2B)x+(A2C). 6x^2 - 7x = A(x^2 + 1) + (Bx + C)(x-2) = (A+B)x^2 + (C - 2B)x + (A - 2C). Equating coefficients, we obtain the system {A+  B          =6 2B +  C=7A          2C=0\left \{ \begin{array}{rcl} A + \ \ B \ \ \ \ \ \ \ \ \ \ & = & 6 \\ - \ 2B \ + \ \ C & = & -7 \\ A \ \ \ \ \ \ \ \ \ \ - 2C & = & 0 \end{array} \right . We again use SageMath to solve this system.

A,B,C = var('A','B','C') eq1 = ## Insert Equation 1 here eq2 = ## Insert Equation 2 here eq3 = ## Insert Equation 3 here solve([eq1, eq2, eq3], [A, B, C])

You should get that A=2,B=4,A = 2, B = 4, and C=1C = 1. Therefore, we have 6x27x(x2)(x2+1) dx=2x2 dx+4x+1x2+1 dx.\int \dfrac{6x^2 - 7x}{(x-2)(x^2 + 1)} \ dx = \int \dfrac{2}{x-2} \ dx + \int \dfrac{4x + 1}{x^2 + 1} \ dx. The first integral on the right side is simply 2lnx2.2 \ln|x-2|. In order to evaluate the second integral, we first need to split the fraction into the sum of two fractions. Note that 4x+1x2+1 dx=4xx2+1 dx+1x2+1 dx=2lnx2+1+tan1(x)+C,\int \dfrac{4x + 1}{x^2 + 1} \ dx = \int \dfrac{4x}{x^2 + 1} \ dx + \int \dfrac{1}{x^2 + 1} \ dx = 2 \ln|x^2 + 1| + \tan^{-1}(x) + C, where we used uu-substitution to evaluate the first integral. Therefore, we have that 6x27xx32x2+x2 dx=2lnx2+2lnx2+1+tan1(x)+C.\int \dfrac{6x^2 - 7x}{x^3 - 2x^2 + x - 2} \ dx = 2\ln |x-2| + 2\ln|x^2 + 1| + \tan^{-1}(x) + C. Use SageMath to check that this answer is correct.

Example 3

Suppose that we are trying to integrate f(x)=6x3+50x2+136x+128x4+8x3+18x227.f(x) = \dfrac{6x^3 + 50x^2 + 136x + 128}{x^4 + 8x^3 + 18x^2 - 27}. Again, we will start by determining the partial fraciton decomposition of f(x)f(x). First, we must factor denom(x)=x4+8x3+18x227.denom(x) = x^4 + 8x^3 + 18x^2 - 27. Let's plot denom(x)denom(x) and try to determine xx-intercepts.

def denom(x): return x^4 + 8*x^3 + 18*x^2 - 27 plot(denom(x), xmin=-5, xmax=5, ymin = -5, ymax = 5)

We can see that both x=3x = -3 and x=1x = 1 are xx-intercepts. Therefore, denom(x)=(x+3)(x1)denom2(x)denom(x) = (x+3)(x-1)denom_2(x) for some polynomial denom2(x)denom_2(x).

denom2(x) = denom(x) / ((x+3)*(x-1)) denom2(x).full_simplify()

Thus, denom(x)=(x+3)(x1)(x2+6x+9)denom(x) = (x+3)(x-1)(x^2 + 6x + 9). We can factor the quadratic x2+6x+9x^2 + 6x + 9 and obtain (x+3)2(x+3)^2. Therefore, we have that d(x)=(x+3)3(x1).d(x) = (x+3)^3(x-1). It follows that f(x)=6x3+50x2+136x+128(x+3)3(x1).f(x) = \dfrac{6x^3 + 50x^2 + 136x + 128}{(x+3)^3(x-1)}. Recall that the general form of the partial fraction of f(x)f(x) is 6x3+50x2+136x+128(x+3)3(x1)=Ax+3+B(x+3)2+C(x+3)3+D(x1).\dfrac{6x^3 + 50x^2 + 136x + 128}{(x+3)^3(x-1)} = \dfrac{A}{x+3} + \dfrac{B}{(x+3)^2} + \dfrac{C}{(x+3)^3} + \dfrac{D}{(x-1)}. Note:\textbf{Note:} you may not have covered the general form of a repeated linear term like (x+3)3(x+3)^3 in your class. When we have a repeated linear, the general form is a constant over each power of the linear term up to the power to which it is being raised.

Continue solving the problem by setting up a system of four linear equations and solving for A,B,C,A, B, C, and DD. Then, use the partial fraction decomposition to integrate f(x)f(x).

Example 4

For each of the rational functions below, first find the partial fraction decomposition of the function by solving a system of linear equations. Then, integrate the function by hand and use SageMath to check that your integration is correct.

  1. f1(x)=7x+4x2x6f1(x) = \dfrac{7x+4}{x^2 - x - 6}

  2. f2(x)=5x2+100x49x3+2x271x72f2(x) = \dfrac{5x^2 + 100x - 49}{x^3+ 2x^2 - 71x - 72}

  3. f3(x)=3x2x+21x3+3xf3(x) = \dfrac{3x^2 - x + 21}{x^3 + 3x}

  4. f4(x)=5x32x2+4x1x4x2f4(x) = \dfrac{5x^3 - 2x^2 + 4x - 1}{x^4 - x^2}