Skip to content
Family Table Math

Integrating with Long Division and Completing the Square

Some rational functions don’t fit any basic rule or an obvious substitution as they stand. Two algebra tools from earlier courses fix that. Long division splits a “top-heavy” fraction into a polynomial plus a simpler fraction. Completing the square turns a quadratic denominator into the form (x−h)2+a2(x - h)^2 + a^2, which integrates to an arctangent.

For a linear denominator (from a quick substitution u=ax+bu = ax + b):

∫1ax+b dx=1aln⁡∣ax+b∣+C\int \frac{1}{ax + b}\,dx = \frac{1}{a}\ln|ax + b| + C

For a sum of squares (from ∫11+u2 du=arctan⁡u+C\int \tfrac{1}{1 + u^2}\,du = \arctan u + C with u=xau = \tfrac{x}{a}):

∫1x2+a2 dx=1aarctan⁡ ⁣(xa)+C(a>0)\int \frac{1}{x^2 + a^2}\,dx = \frac{1}{a}\arctan\!\left(\frac{x}{a}\right) + C \qquad (a \gt 0)

Here’s where the second one comes from. Factor out a2a^2 and let u=xau = \tfrac{x}{a}, so dx=a dudx = a\,du:

∫1a2(1+x2a2) dx=1a2∫a du1+u2=1aarctan⁡u+C\int \frac{1}{a^2\left(1 + \frac{x^2}{a^2}\right)}\,dx = \frac{1}{a^2}\int \frac{a\,du}{1 + u^2} = \frac{1}{a}\arctan u + C

If the degree of the numerator is greater than or equal to the degree of the denominator, divide first. The result is

numeratordenominator=quotient+remainderdenominator,\frac{\text{numerator}}{\text{denominator}} = \text{quotient} + \frac{\text{remainder}}{\text{denominator}},

and both pieces are easy to integrate. You can use long division, synthetic division, or just rewrite the numerator cleverly (for example, x+3x+1=(x+1)+2x+1=1+2x+1\frac{x + 3}{x + 1} = \frac{(x + 1) + 2}{x + 1} = 1 + \frac{2}{x + 1}).

If the denominator is a quadratic with no real zeros (its discriminant is negative), complete the square:

x2+bx+c=(x+b2)2+(c−b24)x^2 + bx + c = \left(x + \frac{b}{2}\right)^2 + \left(c - \frac{b^2}{4}\right)

Then substitute u=x+b2u = x + \tfrac{b}{2} (so du=dxdu = dx) and use the arctangent integral.

If the numerator is a linear term, first split off a multiple of the derivative of the denominator (which gives a logarithm), and complete the square on what’s left (see Practice 9).

What you seeWhat to do
Numerator degree ≥ denominator degreeLong division first
Numerator is a multiple of the denominator’s derivativeSubstitution, giving a ln⁡\ln
11 over a quadratic with no real zerosComplete the square, giving an arctan⁡\arctan

AP Calculus AB only asks for these cases. Denominators that factor into distinct (non-repeating) linear factors usually need partial fractions, which is BC-only.

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

Solution. The top has degree 22 and the bottom degree 11, so divide. Since (x+1)(x+2)=x2+3x+2(x + 1)(x + 2) = x^2 + 3x + 2,

x2+3x+1=(x+1)(x+2)−1⇒x2+3x+1x+1=x+2−1x+1.x^2 + 3x + 1 = (x + 1)(x + 2) - 1 \quad\Rightarrow\quad \frac{x^2 + 3x + 1}{x + 1} = x + 2 - \frac{1}{x + 1}. ∫(x+2−1x+1)dx=x22+2x−ln⁡∣x+1∣+C\int \left(x + 2 - \frac{1}{x + 1}\right)dx = \frac{x^2}{2} + 2x - \ln|x + 1| + C

Find (a) ∫1x2+9 dx\displaystyle\int \frac{1}{x^2 + 9}\,dx and (b) ∫14x2+1 dx\displaystyle\int \frac{1}{4x^2 + 1}\,dx.

Solution.

(a) This is 1x2+a2\dfrac{1}{x^2 + a^2} with a=3a = 3:

∫1x2+9 dx=13arctan⁡ ⁣(x3)+C\int \frac{1}{x^2 + 9}\,dx = \frac{1}{3}\arctan\!\left(\frac{x}{3}\right) + C

(b) Write 4x2=(2x)24x^2 = (2x)^2 and let u=2xu = 2x, so dx=12 dudx = \tfrac{1}{2}\,du:

∫1(2x)2+1 dx=12∫1u2+1 du=12arctan⁡(2x)+C\int \frac{1}{(2x)^2 + 1}\,dx = \frac{1}{2}\int \frac{1}{u^2 + 1}\,du = \frac{1}{2}\arctan(2x) + C

Find ∫1x2+6x+13 dx\displaystyle\int \frac{1}{x^2 + 6x + 13}\,dx.

Solution. The discriminant is 36−52<036 - 52 \lt 0, so the denominator doesn’t factor. Complete the square:

x2+6x+13=(x2+6x+9)+4=(x+3)2+22x^2 + 6x + 13 = (x^2 + 6x + 9) + 4 = (x + 3)^2 + 2^2

Let u=x+3u = x + 3, du=dxdu = dx:

∫1u2+22 du=12arctan⁡ ⁣(u2)+C=12arctan⁡ ⁣(x+32)+C\int \frac{1}{u^2 + 2^2}\,du = \frac{1}{2}\arctan\!\left(\frac{u}{2}\right) + C = \frac{1}{2}\arctan\!\left(\frac{x + 3}{2}\right) + C

Evaluate ∫131x2−2x+5 dx\displaystyle\int_1^3 \frac{1}{x^2 - 2x + 5}\,dx.

Solution. Complete the square: x2−2x+5=(x−1)2+4x^2 - 2x + 5 = (x - 1)^2 + 4. With u=x−1u = x - 1, the limits become u=0u = 0 and u=2u = 2:

∫021u2+4 du=[12arctan⁡u2]02=12arctan⁡1−12arctan⁡0=12⋅π4=π8\int_0^2 \frac{1}{u^2 + 4}\,du = \left[\frac{1}{2}\arctan\frac{u}{2}\right]_0^2 = \frac{1}{2}\arctan 1 - \frac{1}{2}\arctan 0 = \frac{1}{2} \cdot \frac{\pi}{4} = \frac{\pi}{8}

(Arctangent values are in radians: arctan⁡1=π4\arctan 1 = \tfrac{\pi}{4}.)

Skipping the division. ∫x2x+1 dx\int \frac{x^2}{x + 1}\,dx is not x33ln⁡∣x+1∣\frac{x^3}{3}\ln|x + 1| or anything like it. When the top’s degree is at least the bottom’s, divide first.

Forgetting the remainder. After dividing, the remainder term is usually where the logarithm comes from. Check your division by multiplying back.

Losing the 1/a. ∫1x2+9 dx=13arctan⁡x3+C\int \frac{1}{x^2 + 9}\,dx = \frac{1}{3}\arctan\frac{x}{3} + C. Both the 13\frac{1}{3} in front and the x3\frac{x}{3} inside are needed.

Using ln for every fraction. ∫1x2+4 dx\int \frac{1}{x^2 + 4}\,dx is not ln⁡(x2+4)\ln(x^2 + 4); the numerator isn’t the derivative of the denominator. A logarithm appears only when the top is a multiple of the bottom’s derivative.

Errors completing the square. Half the xx-coefficient, square it, add and subtract. For x2−2x+5x^2 - 2x + 5: (x−1)2−1+5=(x−1)2+4(x - 1)^2 - 1 + 5 = (x - 1)^2 + 4.

1. (Warm-up) Find ∫3x−5 dx\displaystyle\int \frac{3}{x - 5}\,dx.

Solution3ln⁡∣x−5∣+C3\ln|x - 5| + C

2. (Warm-up) Find ∫1x2+16 dx\displaystyle\int \frac{1}{x^2 + 16}\,dx.

Solution

With a=4a = 4:

14arctan⁡ ⁣(x4)+C\frac{1}{4}\arctan\!\left(\frac{x}{4}\right) + C

3. (Warm-up) Find ∫x+3x+1 dx\displaystyle\int \frac{x + 3}{x + 1}\,dx.

Solution

x+3x+1=(x+1)+2x+1=1+2x+1\dfrac{x + 3}{x + 1} = \dfrac{(x + 1) + 2}{x + 1} = 1 + \dfrac{2}{x + 1}:

∫(1+2x+1)dx=x+2ln⁡∣x+1∣+C\int \left(1 + \frac{2}{x + 1}\right)dx = x + 2\ln|x + 1| + C

4. (Core) Find ∫x2−4x+7x−2 dx\displaystyle\int \frac{x^2 - 4x + 7}{x - 2}\,dx.

Solution

x2−4x+7=(x−2)2+3=(x−2)(x−2)+3x^2 - 4x + 7 = (x - 2)^2 + 3 = (x - 2)(x - 2) + 3, so

x2−4x+7x−2=x−2+3x−2.\frac{x^2 - 4x + 7}{x - 2} = x - 2 + \frac{3}{x - 2}.∫(x−2+3x−2)dx=x22−2x+3ln⁡∣x−2∣+C\int \left(x - 2 + \frac{3}{x - 2}\right)dx = \frac{x^2}{2} - 2x + 3\ln|x - 2| + C

5. (Core) Find ∫x2+2x2+1 dx\displaystyle\int \frac{x^2 + 2}{x^2 + 1}\,dx.

Solution

The degrees are equal, so divide: x2+2x2+1=(x2+1)+1x2+1=1+1x2+1\dfrac{x^2 + 2}{x^2 + 1} = \dfrac{(x^2 + 1) + 1}{x^2 + 1} = 1 + \dfrac{1}{x^2 + 1}.

∫(1+1x2+1)dx=x+arctan⁡x+C\int \left(1 + \frac{1}{x^2 + 1}\right)dx = x + \arctan x + C

6. (Core) Find ∫1x2+4x+8 dx\displaystyle\int \frac{1}{x^2 + 4x + 8}\,dx.

Solution

x2+4x+8=(x+2)2+4x^2 + 4x + 8 = (x + 2)^2 + 4. With u=x+2u = x + 2:

∫1u2+22 du=12arctan⁡ ⁣(x+22)+C\int \frac{1}{u^2 + 2^2}\,du = \frac{1}{2}\arctan\!\left(\frac{x + 2}{2}\right) + C

7. (Core) Find ∫x3+2x2+1x+2 dx\displaystyle\int \frac{x^3 + 2x^2 + 1}{x + 2}\,dx.

Solution

x3+2x2=x2(x+2)x^3 + 2x^2 = x^2(x + 2), so x3+2x2+1=x2(x+2)+1x^3 + 2x^2 + 1 = x^2(x + 2) + 1 and

x3+2x2+1x+2=x2+1x+2.\frac{x^3 + 2x^2 + 1}{x + 2} = x^2 + \frac{1}{x + 2}.∫(x2+1x+2)dx=x33+ln⁡∣x+2∣+C\int \left(x^2 + \frac{1}{x + 2}\right)dx = \frac{x^3}{3} + \ln|x + 2| + C

8. (Challenge) Evaluate ∫01x3x2+1 dx\displaystyle\int_0^1 \frac{x^3}{x^2 + 1}\,dx.

Solution

Divide: x3=x(x2+1)−xx^3 = x(x^2 + 1) - x, so x3x2+1=x−xx2+1\dfrac{x^3}{x^2 + 1} = x - \dfrac{x}{x^2 + 1}.

For the second piece, u=x2+1u = x^2 + 1 gives ∫xx2+1 dx=12ln⁡(x2+1)\int \dfrac{x}{x^2 + 1}\,dx = \tfrac{1}{2}\ln(x^2 + 1).

∫01(x−xx2+1)dx=[x22−12ln⁡(x2+1)]01=12−12ln⁡2≈0.153\int_0^1 \left(x - \frac{x}{x^2 + 1}\right)dx = \left[\frac{x^2}{2} - \frac{1}{2}\ln(x^2 + 1)\right]_0^1 = \frac{1}{2} - \frac{1}{2}\ln 2 \approx 0.153

9. (Challenge) Find ∫2x+6x2+2x+5 dx\displaystyle\int \frac{2x + 6}{x^2 + 2x + 5}\,dx.

Solution

The derivative of the denominator is 2x+22x + 2. Split the numerator: 2x+6=(2x+2)+42x + 6 = (2x + 2) + 4.

∫2x+2x2+2x+5 dx+∫4x2+2x+5 dx\int \frac{2x + 2}{x^2 + 2x + 5}\,dx + \int \frac{4}{x^2 + 2x + 5}\,dx

The first is a logarithm (u=x2+2x+5u = x^2 + 2x + 5): ln⁡(x2+2x+5)\ln(x^2 + 2x + 5). No absolute value is needed, because x2+2x+5=(x+1)2+4x^2 + 2x + 5 = (x + 1)^2 + 4 is always positive.

For the second, complete the square: ∫4(x+1)2+4 dx=4⋅12arctan⁡ ⁣(x+12)\displaystyle\int \frac{4}{(x + 1)^2 + 4}\,dx = 4 \cdot \frac{1}{2}\arctan\!\left(\frac{x + 1}{2}\right).

∫2x+6x2+2x+5 dx=ln⁡(x2+2x+5)+2arctan⁡ ⁣(x+12)+C\int \frac{2x + 6}{x^2 + 2x + 5}\,dx = \ln(x^2 + 2x + 5) + 2\arctan\!\left(\frac{x + 1}{2}\right) + C