Completing the square

Completing the square is an algebraic technique used to solve quadratic equations, in analytic geometry for determining the shapes of graphs, and in calculus for computing integrals. The essential objective is to reduce a quadratic polynomial in a variable in an equation or expression to a squared polynomial of linear order. This can reduce an equation or integral to one that is more easily solved or evaluated.

The purpose of completing the square is to fill in the following blank:


 * $$ax^2 + bx + c = a(\cdots\cdots)^2 + \mbox{constant}.\,$$

The expression that will replace the blank depends of course on the variable x. The "constant" does not; that is why it is a "constant".

This amounts to solving the following equation for k1 and k2:


 * $$ax^2 + bx + c = a(x + k_1)^2 + k_2,\,$$

where a, b, c are known. This is an identity in x, meaning that it should be true for all x.

Overview
In elementary algebra, completing the square is a technique in which an expression involving a quadratic polynomial is transformed to one involving a squared linear polynomial and a constant. It converts a polynomial fragment of the form


 * $$a x^2 + b x\,\!$$

to one of the form


 * $$(c x + d)^2 + e\,\!$$

The coefficients a, b, c, d and e above can be expressions in their own right, containing variables other than x.

Completing the square is commonly used to derive the quadratic formula, which solves a quadratic equation.


 * $$\begin{align}

ax^2+bx+c &{}= 0\\ ax^2+bx &{}= -c\\ x^2 + \left( \frac{b}{a} \right) x &{}= -\frac{c}{a}\\ \end{align}$$ The objective is to make the left side of the equation a perfect square. Since the perfect square in question has the form (x + y)2 = x2 + 2xy + y2 for some y, it follows that 2xy = (b/a)x, and thus y = b/2a. Adding y2 = (b/2a)2 to both sides yields


 * $$\begin{align}

x^2 + \frac{b}{a} x + \left(\frac{b}{2a}\right)^2 &{}= \left(\frac{b}{2a}\right)^2 -\frac{c}{a} &\text{complete the square}\\ \left(x + \frac{b}{2a}\right)^2 &{}= \frac{b^2-4ac}{4a^2}\\ x + \frac{b}{2a} &{}= \pm\frac{\sqrt{b^2-4ac}}{2a}\\ x &{}= \frac{-b \pm \sqrt{b^2-4ac}}{2a} \end{align}$$

This resultant expression is called the quadratic formula.

Geometric perspective


Consider completing the square for the equation


 * $$x^2 + bx = a.\,$$

Since x2 represents the area of a square with side of length x, and bx represents the area of a rectangle with sides b and x, the process of completing the square can be viewed as visual manipulation of rectangles.

Simple attempts to combine the x2 and the bx rectangles into a larger square result in a missing corner. The term (b/2)2 added to each side of the above equation is precisely the area of the missing corner, whence derives the terminology "completing the square". 

Description
To achieve


 * $$a x^2 + b x = (c x + d)^2 + e, \,\!$$

we must set



\begin{align} c &{}= \sqrt{a} ,\\ d &{}= \frac{b}{2\sqrt{a}} ,\\ e &{}= -d^2\\ &{}= -\left(\frac{b}{2\sqrt{a}}\right)^2\\ &{}= -\frac{b^2}{4a}. \end{align}$$

This gives


 * $$a x^2 + b x = \left(\sqrt{a}\,x + \frac{b}{2 \sqrt{a}}\right)^2 -

\frac{b^2}{4a}. \,\!$$

Proof
Note that


 * $$\left(cx + d\right)^2 + e = c^2 x^2 + 2cdx + d^2 + e .$$

In order to get


 * $$c^2 x^2 + 2cdx + d^2 + e\!$$

into the form


 * $$ax^2 + bx + f ,\!$$

we must perform the following substitutions:



\begin{align} a &{}= c^2 ,\\ b &{}= 2cd ,\\ f &{}= d^2 + e. \end{align}$$

Now that a, b and f are related to c, d and e, we can find c, d and e in terms of a, b, and f algebraically:



\begin{align} c &{}= \pm \sqrt{a} ,\\ d &{}= \frac{b}{2c}\\ &{}= \pm \frac{b}{2\sqrt{a}} ,\\ e &{}= f - d^2\\ &{}= f - \frac{b^2}{4a} \end{align}$$

Iff f equals zero and a is positive, then these equations are equivalent to the above. If a is negative, then the ± signs in the equations for c and d will both represent subtraction—however, the value of $$(cx+d)^2$$ is unaffected if both c and d are negated, so the ± signs are unnecessary.

Concrete example

 * $$\begin{align}5x^2 + 7x - 6 &{}= 5\left(x^2 + {7 \over 5}x\right) -6 \\

&{}= 5\left(x^2 + {7 \over 5}x +\left({7 \over 10}\right)^2\right) - 6 - 5\left({7 \over 10}\right)^2 \\ &{}= 5\left(x + {7 \over 10}\right)^2 - 6 - {7^2 \over 2\cdot 10} \\ &{}= 5\left(x + {7 \over 10}\right)^2 - {6\cdot 20 + 7^2 \over 20} \\ &{}= 5\left(x + {7 \over 10}\right)^2 - {169 \over 20}. \end{align} $$

With this we can find the values of x that produce zero, the roots of the polynomial.



\begin{align} 5x^2 + 7x - 6 &{}= 0\\ 5\left(x + {7 \over 10}\right)^2 - {169 \over 20} &{}= 0\\ \left(x + {7 \over 10}\right)^2 &{}= {169 \over 100}\\ &{}= \left({13 \over 10}\right)^2\\ x + {7 \over 10} &{}= \pm {13 \over 10}\\ x &{}= {-7 \pm 13 \over 10}\\ &{}= {3 \over 5}\mbox{ or }-2. \end{align}$$

We can also find the x value where the function defined by the polynomial,


 * $$y = 5x^2 + 7x - 6, \,\!$$

achieves its most extreme values. The highest power, x2, has a positive coefficient, so large positive or negative values of x produce large values of y. Thus the interesting extreme is the minimum value for y. From the squared form,


 * $$y = 5\left(x + \frac{7}{10}\right)^2 - \frac{169}{20}, $$

we see that if


 * $$x = -{7 \over 10}, $$

then y = &minus;169/20 = &minus;8.45; but if x is any other number, then y is &minus;169/20 plus a nonzero square. Since squares of nonzero real numbers are positive, it must be that whenever x is any other number than &minus;7/10, then y > &minus;8.45. Thus the point (x, y) = (&minus;7/10, &minus;169/20) = (&minus;0.7, &minus;8.45) has the minimum possible value of y.

Calculus example
Consider the problem of finding this antiderivative:


 * $$\int\frac{1}{9x^2-90x+241}\,dx.\,\!$$

This can be done by completing the square of the denominator. The denominator is


 * $$9x^2-90x+241=9(x^2-10x)+241.\,\!$$

Completing the square by adding (10/2)2 = 25 to x2−10x gives a perfect square, x2 − 10x + 25 = (x − 5)2. The denominator becomes



\begin{align} 9(x^2-10x)+241 &{}=9(x^2-10x+25)+241-9(25)\\ &{}=9(x-5)^2+16. \end{align}$$

So our integral is



\begin{align} \int\frac{1}{9x^2-90x+241}\,dx &{}=\frac{1}{9}\int\frac{1}{(x-5)^2+(4/3)^2}\,dx\\ &{}=\frac{1}{9}\cdot\frac{3}{4}\arctan\frac{3(x-5)}{4}+C. \end{align}$$

The point is that the revised denominator allows us to match a known result from a table of integrals,


 * $$\int\frac{1}{u^2+a^2}\,du = \frac{1}{a} \arctan \frac{u}{a} + C .$$

Complex number examples
Consider the expression


 * $$ |z|^2 - b^*z - bz^* + c,\,$$

where z and b are complex numbers, z* and b* are the complex conjugates of z and b, respectively, and c is a real number. Using the identity |u|2 = uu* we can rewrite this as


 * $$ |z-b|^2 - |b|^2 + c, \,\!$$

which is clearly a real quantity. This is because



\begin{align} |z-b|^2 &{}= (z-b)(z-b)^*\\ &{}= (z-b)(z^*-b^*)\\ &{}= zz^* - zb^* - bz^* + bb^*\\ &{}= |z|^2 - zb^* - bz^* + |b|^2. \end{align}$$

As another example, the expression


 * $$ ax^2 + by^2 + c, \,\!$$

where a, b, c, x, and y are real numbers, with a &gt; 0 and b &gt; 0, may be expressed in terms of the square of the absolute value of a complex number. Define


 * $$ z = \sqrt{a}\,x + i \sqrt{b} \,y . $$

Then



\begin{align} |z|^2 &{}= z z^*\\ &{}= (\sqrt{a}\,x + i \sqrt{b}\,y)(\sqrt{a}\,x - i \sqrt{b}\,y) \\ &{}= ax^2 - i\sqrt{ab}\,xy + i\sqrt{ba}\,yx - i^2by^2 \\ &{}= ax^2 + by^2 , \end{align}$$

so


 * $$ ax^2 + by^2 + c = |z|^2 + c . \,\!$$

A variation on the technique
As conventionally taught, completing the square consists of adding the third term, v2 to


 * $$u^2 + 2uv\,$$

to get a square. There are also cases in which one can add the middle term, either 2uv or &minus;2uv, to


 * $$u^2 + v^2\,$$

to get a square.

Example: the sum of a positive number and its reciprocal
By writing



\begin{align} x + {1 \over x} &{} = \left(x - 2 + {1 \over x}\right) + 2\\ &{}= \left(\sqrt{x} - {1 \over \sqrt{x}}\right)^2 + 2 \end{align}$$

we show that the sum of a positive number x and its reciprocal is always greater than or equal to 2. The square of a real expression is always greater than or equal to zero, which gives the stated bound; and here we achieve 2 just when x is 1, causing the square to vanish.

Example: factoring a simple quartic polynomial
Consider the problem of factoring the polynomial


 * $$x^4 + 324 . \,\!$$

This is


 * $$(x^2)^2 + (18)^2, \,\!$$

so the middle term is 2(x2)(18) = 36x2. Thus we get


 * $$\begin{align} x^4 + 324 &{}= (x^4 + 36x^2 + 324 ) - 36x^2 \\

&{}= (x^2 + 18)^2 - (6x)^2 =\text{a difference of two squares} \\ &{}= (x^2 + 18 + 6x)(x^2 + 18 - 6x) \\ &{}= (x^2 + 6x + 18)(x^2 - 6x + 18) \end{align}$$

(the last line being added merely to follow the convention of decreasing degrees of terms).