# Integration by Completing the Square

By changing the square, we may rewrite any quadratic polynomial $$a{x^2} + {bx} + c$$ in the form

${a\left( {{u^2} + {k}} \right),\;\;}\kern0pt{\text{where}\;\;u = x + \frac{b}{{2a}},\;\;}\kern0pt{k = \frac{{4ac – {b^2}}}{{4{a^2}}}.}$

Completing the square helps when quadratic functions are involved in the integrand.

When the integrand is a rational function with a quadratic expression in the denominator, we can use the following table integrals:

${1.\;\int {\frac{{dx}}{{\sqrt {{x^2} \pm {a^2}} }}} }={ \ln \left| {x + \sqrt {{x^2} \pm {a^2}} } \right|}$

${{2.\;\int {\frac{{dx}}{{\sqrt {{a^2} – {x^2}} }}} }={ \arcsin \frac{x}{a}}}$

${{3.\;\int {\frac{{dx}}{{{a^2} + {x^2}}}} }={ \frac{1}{a}\arctan \frac{x}{a}}}$

${{4.\;\int {\frac{{dx}}{{{a^2} – {x^2}}}} }={ \frac{1}{{2a}}\ln \left| {\frac{{a + x}}{{a – x}}} \right|}}$

Certain other types of integrals involving quadratic functions can be evaluated using trigonometric and hyperbolic substitutions.

## Solved Problems

Click or tap a problem to see the solution.

### Example 1

Find the integral $$\int {\large{\frac{{dx}}{{{x^2} – 5x + 7}}}}\normalsize.$$

### Example 2

Evaluate the integral $$\int {\large{\frac{{dx}}{{{x^2} – x + 2}}}\normalsize}.$$

### Example 3

Evaluate the integral $$\int {\large{\frac{{dx}}{{{x^2} + 10x + 26}}}\normalsize}.$$

### Example 4

Evaluate the integral $$\int {\large{\frac{{dx}}{{5 – 4x – {x^2}}}}\normalsize}.$$

### Example 5

Find the integral $$\int {\large{\frac{{dx}}{{\sqrt {{x^2} + x – 2} }}}\normalsize}.$$

### Example 6

Find the integral $$\int {\large{\frac{{dx}}{{8 – 2x – {x^2}}}}\normalsize}.$$

### Example 7

Find the integral $$\int {\large{\frac{{dx}}{{\sqrt {1 – 2x – {x^2}} }}}\normalsize}.$$

### Example 8

Evaluate the integral $$\int {\large{\frac{{x + 1}}{{{x^2} + x + 1}}}\normalsize dx}.$$

### Example 9

Evaluate the integral $$\int {\large{\frac{xdx}{{{x^2} + 2x + 10}}}\normalsize}.$$

### Example 10

Compute the integral $$\int {\large{\frac{{xdx}}{{\sqrt {5 + x – {x^2}} }}}\normalsize}.$$

### Example 11

Compute the integral $$\int {\large{\frac{{x + 1}}{{\sqrt {{x^2} + 4x + 8} }}}\normalsize dx}.$$

### Example 1.

Find the integral $$\int {\large{\frac{{dx}}{{{x^2} – 5x + 7}}}}\normalsize.$$

Solution.

We complete the square in the denominator:

${{x^2} – 5x + 7 }={ {x^2} – 2 \cdot \frac{5}{2}x + {\left( {\frac{5}{2}} \right)^2} }-{ {\left( {\frac{5}{2}} \right)^2} + 7 }={ {\left( {x – \frac{5}{2}} \right)^2} + 7 – \frac{{25}}{4} }={ {\left( {x – \frac{5}{2}} \right)^2} + \frac{{28 – 25}}{4} }={ {\left( {x – \frac{5}{2}} \right)^2} + {\left( {\frac{{\sqrt 3 }}{2}} \right)^2}.}$

Make the substitution $$u = x – \large{\frac{5}{2}}\normalsize.$$ Then $$du = dx,$$ and the integral in $$u-$$terms becomes

${\int {\frac{{dx}}{{{x^2} – 5x + 7}}} }={ \int {\frac{{dx}}{{{{\left( {x – \frac{5}{2}} \right)}^2} + {{\left( {\frac{{\sqrt 3 }}{2}} \right)}^2}}}} }={ \int {\frac{{du}}{{{u^2} + {{\left( {\frac{{\sqrt 3 }}{2}} \right)}^2}}}} .}$

We can easily evaluate the last integral:

${\int {\frac{{du}}{{{u^2} + {{\left( {\frac{{\sqrt 3 }}{2}} \right)}^2}}}} }={ \frac{1}{{\frac{{\sqrt 3 }}{2}}}\arctan \frac{u}{{\frac{{\sqrt 3 }}{2}}} + C }={ \frac{2}{{\sqrt 3 }}\arctan \frac{{x – \frac{5}{2}}}{{\frac{{\sqrt 3 }}{2}}} + C }={ \frac{2}{{\sqrt 3 }}\arctan \frac{{2x – 5}}{{\sqrt 3 }} + C.}$

### Example 2.

Evaluate the integral $$\int {\large{\frac{{dx}}{{{x^2} – x + 2}}}\normalsize}.$$

Solution.

We complete the square in the quadratic expression:

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

Making the substitution

${u = x – \frac{1}{2},\;\;}\kern0pt{du = dx,}$

we find the integral:

${\int {\frac{{dx}}{{{x^2} – x + 2}}} }={ \int {\frac{{dx}}{{{{\left( {x – \frac{1}{2}} \right)}^2} + {{\left( {\frac{{\sqrt 7 }}{2}} \right)}^2}}}} }={ \int {\frac{{du}}{{{u^2} + {{\left( {\frac{{\sqrt 7 }}{2}} \right)}^2}}}} }={ \frac{1}{{\frac{{\sqrt 7 }}{2}}}\arctan \frac{u}{{\frac{{\sqrt 7 }}{2}}} + C }={ \frac{2}{{\sqrt 7 }}\arctan \frac{{x – \frac{1}{2}}}{{\frac{{\sqrt 7 }}{2}}} + C }={ \frac{2}{{\sqrt 7 }}\arctan \frac{{2x – 1}}{{\sqrt 7 }} + C.}$

### Example 3.

Evaluate the integral $$\int {\large{\frac{{dx}}{{{x^2} + 10x + 26}}}\normalsize}.$$

Solution.

We complete the square in the denominator:

${x^2} + 10x + 26 = {x^2} + 10x + 25 + 1 = {\left( {x + 5} \right)^2} + 1,$

so the integral is written as

${I = \int {\frac{{dx}}{{{x^2} + 10x + 26}}} }={ \int {\frac{{dx}}{{{{\left( {x + 5} \right)}^2} + 1}}} .}$

Using the substitution

${u = x + 5,\;\;}\kern0pt{du = dx,}$

we have

${I = \int {\frac{{du}}{{{u^2} + 1}}} }={ \arctan u + C }={ \arctan \left( {x + 5} \right) + C.}$

### Example 4.

Evaluate the integral $$\int {\large{\frac{{dx}}{{5 – 4x – {x^2}}}}\normalsize}.$$

Solution.

First we complete the square in the denominator:

${5 – 4x – {x^2} }={ 5 – \left( {{x^2} + 4x} \right) }={ 9 – \left( {{x^2} + 4x + 4} \right) }={ 9 – {\left( {x + 2} \right)^2} }={ {3^2} – {\left( {x + 2} \right)^2}.}$

Then the integral becomes

${I = \int {\frac{{dx}}{{5 – 4x – {x^2}}}} }={ \int {\frac{{dx}}{{{3^2} – {{\left( {x + 2} \right)}^2}}}} .}$

Using

${u = x + 2,\;\;}\kern0pt{du = dx,}$

we obtain

${I = \int {\frac{{du}}{{{3^2} – {u^2}}}} }={ \frac{1}{{2 \cdot 3}}\ln \left| {\frac{{3 + u}}{{3 – u}}} \right| + C }={ \frac{1}{6}\ln \left| {\frac{{3 + x + 2}}{{3 – \left( {x + 2} \right)}}} \right| + C }={ \frac{1}{6}\ln \left| {\frac{{5 + x}}{{1 – x}}} \right| + C.}$

### Example 5.

Find the integral $$\int {\large{\frac{{dx}}{{\sqrt {{x^2} + x – 2} }}}\normalsize}.$$

Solution.

Complete the square in the denominator:

${{x^2} + x – 2 }={ \left( {{x^2} + x + \frac{1}{4}} \right) – \frac{1}{4} – 2 }={ {\left( {x + \frac{1}{2}} \right)^2} – \frac{9}{4} }={ {\left( {x + \frac{1}{2}} \right)^2} – {\left( {\frac{3}{2}} \right)^2}.}$

Making the substitution

${u = x + \frac{1}{2},\;\;}\kern0pt{du = dx,}$

we obtain

${\int {\frac{{dx}}{{\sqrt {{x^2} + x – 2} }}} }={ \int {\frac{{dx}}{{\sqrt {{{\left( {x + \frac{1}{2}} \right)}^2} – {{\left( {\frac{3}{2}} \right)}^2}} }}} }={ \int {\frac{{du}}{{\sqrt {{u^2} – {{\left( {\frac{3}{2}} \right)}^2}} }}} }={ \ln \left| {u + \sqrt {{u^2} – {{\left( {\frac{3}{2}} \right)}^2}} } \right| + C }={ \ln \left| {x + \frac{1}{2} + \sqrt {{x^2} + x – 2} } \right| + C.}$

### Example 6.

Find the integral $$\int {\large{\frac{{dx}}{{8 – 2x – {x^2}}}}\normalsize}.$$

Solution.

Completing the square in the denominator yields:

${8 – 2x – {x^2} }={ 8 – \left( {{x^2} + 2x} \right) }={ 9 – \left( {{x^2} + 2x + 1} \right) }={ {3^2} – {\left( {x + 1} \right)^2}.}$

Hence, the integral can written in the form

${I = \int {\frac{{dx}}{{8 – 2x – {x^2}}}} }={ \int {\frac{{dx}}{{{3^2} – {{\left( {x + 1} \right)}^2}}}} .}$

Making the substitution

${u = x + 1,\;\;}\kern0pt{du = dx,}$

we have

${I = \int {\frac{{dx}}{{{3^2} – {{\left( {x + 1} \right)}^2}}}} }={ \int {\frac{{du}}{{{3^2} – {u^2}}}} }={ \frac{1}{{2 \cdot 3}}\ln \left| {\frac{{3 + u}}{{3 – u}}} \right| + C }={ \frac{1}{6}\ln \left| {\frac{{3 + x + 1}}{{3 – \left( {x + 1} \right)}}} \right| + C }={ \frac{1}{6}\ln \left| {\frac{{4 + x}}{{2 – x}}} \right| + C.}$

### Example 7.

Find the integral $$\int {\large{\frac{{dx}}{{\sqrt {1 – 2x – {x^2}} }}}\normalsize}.$$

Solution.

Completing the square in the denominator, we get

${1 – 2x – {x^2} }={ 1 – \left( {{x^2} + 2x} \right) }={ 2 – \left( {{x^2} + 2x + 1} \right) }={ 2 – {\left( {x + 1} \right)^2} }={ {\left( {\sqrt 2 } \right)^2} – {\left( {x + 1} \right)^2}.}$

Make the substitution

${u = x + 1,\;\;}\kern0pt{du = dx.}$

Hence

${\int {\frac{{dx}}{{\sqrt {1 – 2x – {x^2}} }}} }={ \int {\frac{{dx}}{{\sqrt {{{\left( {\sqrt 2 } \right)}^2} – {{\left( {x + 1} \right)}^2}} }}} }={ \int {\frac{{du}}{{\sqrt {{{\left( {\sqrt 2 } \right)}^2} – {u^2}} }}} }={ \arcsin \frac{u}{{\sqrt 2 }} + C }={ \arcsin \frac{{x + 1}}{{\sqrt 2 }} + C.}$

### Example 8.

Evaluate the integral $$\int {\large{\frac{{x + 1}}{{{x^2} + x + 1}}}\normalsize dx}.$$

Solution.

The quadratic function in the denominator does not have real roots, so we can’t factor it. Therefore, we complete the square:

${{x^2} + x + 1 }={ {x^2} + x + \frac{1}{4} + \frac{3}{4} }={ {\left( {x + \frac{1}{2}} \right)^2} + {\left( {\frac{{\sqrt 3 }}{2}} \right)^2}.}$

Express the numerator in terms of $${x + \large{\frac{1}{2}}\normalsize}:$$

$x + 1 = \left( {x + \frac{1}{2}} \right) + \frac{1}{2}.$

Using the table integrals, we get

${\int {\frac{{x + 1}}{{{x^2} + x + 1}}dx} }={ \int {\frac{{\left( {x + \frac{1}{2}} \right) + \frac{1}{2}}}{{{x^2} + x + 1}}dx} }={ \int {\frac{{x + \frac{1}{2}}}{{{x^2} + x + 1}}dx} }+{ \frac{1}{2}\int {\frac{{dx}}{{{x^2} + x + 1}}} }={ \frac{1}{2}\int {\frac{{\left( {2x + 1} \right)dx}}{{{x^2} + x + 1}}} }+{ \frac{1}{2}\int {\frac{{dx}}{{{{\left( {x + \frac{1}{2}} \right)}^2} + {{\left( {\frac{{\sqrt 3 }}{2}} \right)}^2}}}} }={ \frac{1}{2}\int {\frac{{d\left( {{x^2} + x + 1} \right)}}{{{x^2} + x + 1}}} }+{ \frac{1}{2}\int {\frac{{d\left( {x + \frac{1}{2}} \right)}}{{{{\left( {x + \frac{1}{2}} \right)}^2} + {{\left( {\frac{{\sqrt 3 }}{2}} \right)}^2}}}} }={ \frac{1}{2}\ln \left| {{x^2} + x + 1} \right| }+{ \frac{1}{2} \cdot \frac{1}{{\frac{{\sqrt 3 }}{2}}}\arctan \frac{{x + \frac{1}{2}}}{{\frac{{\sqrt 3 }}{2}}} + C }={ \frac{1}{2}\ln \left( {{x^2} + x + 1} \right) }+{ \frac{1}{{\sqrt 3 }}\arctan \frac{{2x + 1}}{{\sqrt 3 }} + C.}$

### Example 9.

Evaluate the integral $$\int {\large{\frac{xdx}{{{x^2} + 2x + 10}}}\normalsize}.$$

Solution.

We complete the square in the denominator:

${{x^2} + 2x + 10 }={ {x^2} + 2x + 1 + 9 }={ {\left( {x + 1} \right)^2} + {3^2}.}$

Write the numerator in terms of $${x + 1}:$$

$x = x + 1 – 1.$

Hence, we can split the initial integral into two simpler ones:

${I = \int {\frac{xdx}{{{x^2} + 2x + 10}}} }={ \int {\frac{{x + 1 – 1}}{{{x^2} + 2x + 10}}dx} }={ \int {\frac{{\left( {x + 1} \right)dx}}{{{x^2} + 2x + 10}}} }-{ \int {\frac{{dx}}{{{x^2} + 2x + 10}}} }={ \frac{1}{2}\int {\frac{{\left( {2x + 2} \right)dx}}{{{x^2} + 2x + 10}}} }-{ \int {\frac{{dx}}{{{{\left( {x + 1} \right)}^2} + {3^2}}}} }={ {I_1} – {I_2}.}$

We calculate both integrals separately.

In the first integral, let $$u = {x^2} + 2x + 10.$$ Then $$du = \left( {2x + 2} \right)dx,$$ so that

${{I_1} = \frac{1}{2}\int {\frac{{\left( {2x + 2} \right)dx}}{{{x^2} + 2x + 10}}} }={ \frac{1}{2}\int {\frac{{du}}{u}} }={ \frac{1}{2}\ln \left| u \right| }={ \frac{1}{2}\ln \left| {{x^2} + 2x + 10} \right| }={ \frac{1}{2}\ln \left( {{x^2} + 2x + 10} \right).}$

Using integration formulas from a table of integrals, we can easily evaluate the second integral:

${{I_2} = \int {\frac{{dx}}{{{{\left( {x + 1} \right)}^2} + {3^2}}}} }={ \frac{1}{3}\arctan \frac{{x + 1}}{3}.}$

Then

${I = {I_1} – {I_2} }={ \frac{1}{2}\ln \left( {{x^2} + 2x + 10} \right) }-{ \frac{1}{3}\arctan \frac{{x + 1}}{3} }+{ C.}$

### Example 10.

Compute the integral $$\int {\large{\frac{{xdx}}{{\sqrt {5 + x – {x^2}} }}}\normalsize}.$$

Solution.

Given that

$\left( {5 + x – {x^2}} \right)^\prime = 1 – 2x,$

we split the numerator and write the initial integral as the sum of two integrals:

${I = \int {\frac{{xdx}}{{\sqrt {5 + x – {x^2}} }}} }={ – \frac{1}{2}\int {\frac{{\left( { – 2x} \right)}}{{\sqrt {5 + x – {x^2}} }}dx} }={ – \frac{1}{2}\int {\frac{{\left( { – 2x + 1 – 1} \right)}}{{\sqrt {5 + x – {x^2}} }}dx} }={ – \frac{1}{2}\int {\frac{{\left( {1 – 2x} \right)}}{{\sqrt {5 + x – {x^2}} }}dx} }+{ \frac{1}{2}\int {\frac{{dx}}{{\sqrt {5 + x – {x^2}} }}} }={ {I_1} + {I_2}.}$

To find the first integral $${I_1},$$ we use the substitution

${u = 5 + x – {x^2},\;\;}\kern0pt{du = \left( {1 – 2x} \right)dx.}$

Then

${{I_1} }={ – \frac{1}{2}\int {\frac{{\left( {1 – 2x} \right)}}{{\sqrt {5 + x – {x^2}} }}dx} }={ – \frac{1}{2}\int {\frac{{du}}{{\sqrt u }}} }={ – \sqrt u }={ – \sqrt {5 + x – {x^2}} .}$

To evaluate the second integral $${I_2},$$ we complete the square in the denominator:

${5 + x – {x^2} }={ 5 – \left( {{x^2} – x} \right) }={ 5 + \frac{1}{4} – \left( {{x^2} – x + \frac{1}{4}} \right) }={ \frac{{21}}{4} – {\left( {x – \frac{1}{2}} \right)^2} }={ {\left( {\frac{{\sqrt {21} }}{2}} \right)^2} – {\left( {x – \frac{1}{2}} \right)^2}.}$

Now we can express the integral in terms of the inverse sine function:

${{I_2} = \frac{1}{2}\int {\frac{{dx}}{{\sqrt {5 + x – {x^2}} }}} }={ \frac{1}{2}\int {\frac{{dx}}{{\sqrt {{{\left( {\frac{{\sqrt {21} }}{2}} \right)}^2} – {{\left( {x – \frac{1}{2}} \right)}^2}} }}} }={ \frac{1}{2}\arcsin \frac{{x – \frac{1}{2}}}{{\frac{{\sqrt {21} }}{2}}} }={ \frac{1}{2}\arcsin \frac{{2x – 1}}{{\sqrt {21} }}.}$

The final answer is given by

${I = – \sqrt {5 + x – {x^2}} }+{ \frac{1}{2}\arcsin \frac{{2x – 1}}{{\sqrt {21} }} }+{ C.}$

### Example 11.

Compute the integral $$\int {\large{\frac{{x + 1}}{{\sqrt {{x^2} + 4x + 8} }}}\normalsize dx}.$$

Solution.

We split the numerator and write the initial integral as the sum of two integrals. Notice that

$\left( {{x^2} + 4x + 8} \right)^\prime = 2x + 4.$

Then

${\int {\frac{{x + 1}}{{\sqrt {{x^2} + 4x + 8} }}dx} }={ \frac{1}{2}\int {\frac{{2x + 2}}{{\sqrt {{x^2} + 4x + 8} }}dx} }={ \frac{1}{2}\int {\frac{{2x + 4 – 2}}{{\sqrt {{x^2} + 4x + 8} }}dx} }={ \frac{1}{2}\int {\frac{{2x + 4}}{{\sqrt {{x^2} + 4x + 8} }}dx} }-{ \int {\frac{{dx}}{{\sqrt {{x^2} + 4x + 8} }}} }={ {I_1} – {I_2}.}$

The first integral $${I_1}$$ is solved using the substitution

${u = {x^2} + 4x + 8,\;\;}\kern0pt{du = \left( {2x + 4} \right)dx.}$

Hence

${{I_1} = \frac{1}{2}\int {\frac{{2x + 4}}{{\sqrt {{x^2} + 4x + 8} }}dx} }={ \frac{1}{2}\int {\frac{{du}}{{\sqrt u }}} }={ \sqrt u }={ \sqrt {{x^2} + 4x + 8} .}$

To find the second integral $${I_2},$$ we complete the square in the denominator:

${{x^2} + 4x + 8 }={ \left( {{x^2} + 4x + 4} \right) + 4 }={ {\left( {x + 2} \right)^2} + {2^2}.}$

Making the change $$t = x + 2,$$ $$dt = dx,$$ we obtain

${{I_2} = \int {\frac{{dx}}{{\sqrt {{x^2} + 4x + 8} }}} }={ \int {\frac{{dx}}{{\sqrt {{{\left( {x + 2} \right)}^2} + {2^2}} }}} }={ \int {\frac{{dt}}{{\sqrt {{t^2} + {2^2}} }}} }={ \ln \left| {t + \sqrt {{t^2} + {2^2}} } \right| }={ \ln \left| {x + 2 + \sqrt {{x^2} + 4x + 8} } \right|.}$

So, the initial integral is given by

${I = \sqrt {{x^2} + 4x + 8} }-{ \ln \left| {x + 2 + \sqrt {{x^2} + 4x + 8} } \right| }+{ C.}$