Misplaced Pages

Completing the square

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Method for solving quadratic equations
Animation depicting the process of completing the square. (Details, animated GIF version)

In elementary algebra, completing the square is a technique for converting a quadratic polynomial of the form ⁠ a x 2 + b x + c {\displaystyle \textstyle ax^{2}+bx+c} ⁠ to the form ⁠ a ( x h ) 2 + k {\displaystyle \textstyle a(x-h)^{2}+k} ⁠ for some values of ⁠ h {\displaystyle h} ⁠ and ⁠ k {\displaystyle k} ⁠. In terms of a new quantity ⁠ x h {\displaystyle x-h} ⁠, this expression is a quadratic polynomial with no linear term. By subsequently isolating ⁠ ( x h ) 2 {\displaystyle \textstyle (x-h)^{2}} ⁠ and taking the square root, a quadratic problem can be reduced to a linear problem.

The name completing the square comes from a geometrical picture in which ⁠ x {\displaystyle x} ⁠ represents an unknown length. Then the quantity ⁠ x 2 {\displaystyle \textstyle x^{2}} ⁠ represents the area of a square of side ⁠ x {\displaystyle x} ⁠ and the quantity ⁠ b a x {\displaystyle {\tfrac {b}{a}}x} ⁠ represents the area of a pair of congruent rectangles with sides ⁠ x {\displaystyle x} ⁠ and ⁠ b 2 a {\displaystyle {\tfrac {b}{2a}}} ⁠. To this square and pair of rectangles one more square is added, of side length ⁠ b 2 a {\displaystyle {\tfrac {b}{2a}}} ⁠. This crucial step completes a larger square of side length ⁠ x + b 2 a {\displaystyle x+{\tfrac {b}{2a}}} ⁠.

Completing the square is the oldest method of solving general quadratic equations, used in Old Babylonian clay tablets dating from 1800–1600 BCE, and is still taught in elementary algebra courses today. It is also used for graphing quadratic functions, deriving the quadratic formula, and more generally in computations involving quadratic polynomials, for example in calculus evaluating Gaussian integrals with a linear term in the exponent, and finding Laplace transforms.

History

Further information: Algebra § History

The technique of completing the square was known in the Old Babylonian Empire.

Muhammad ibn Musa Al-Khwarizmi, a famous polymath who wrote the early algebraic treatise Al-Jabr, used the technique of completing the square to solve quadratic equations.

Overview

Background

The formula in elementary algebra for computing the square of a binomial is: ( x + p ) 2 = x 2 + 2 p x + p 2 . {\displaystyle (x+p)^{2}\,=\,x^{2}+2px+p^{2}.}

For example: ( x + 3 ) 2 = x 2 + 6 x + 9 ( p = 3 ) ( x 5 ) 2 = x 2 10 x + 25 ( p = 5 ) . {\displaystyle {\begin{alignedat}{2}(x+3)^{2}\,&=\,x^{2}+6x+9&&(p=3)\\(x-5)^{2}\,&=\,x^{2}-10x+25\qquad &&(p=-5).\end{alignedat}}}

In any perfect square, the coefficient of x is twice the number p, and the constant term is equal to p.

Basic example

Consider the following quadratic polynomial: x 2 + 10 x + 28. {\displaystyle x^{2}+10x+28.}

This quadratic is not a perfect square, since 28 is not the square of 5: ( x + 5 ) 2 = x 2 + 10 x + 25. {\displaystyle (x+5)^{2}\,=\,x^{2}+10x+25.}

However, it is possible to write the original quadratic as the sum of this square and a constant: x 2 + 10 x + 28 = ( x + 5 ) 2 + 3. {\displaystyle x^{2}+10x+28\,=\,(x+5)^{2}+3.}

This is called completing the square.

General description

Given any monic quadratic x 2 + b x + c , {\displaystyle x^{2}+bx+c,} it is possible to form a square that has the same first two terms: ( x + 1 2 b ) 2 = x 2 + b x + 1 4 b 2 . {\displaystyle \left(x+{\tfrac {1}{2}}b\right)^{2}\,=\,x^{2}+bx+{\tfrac {1}{4}}b^{2}.}

This square differs from the original quadratic only in the value of the constant term. Therefore, we can write x 2 + b x + c = ( x + 1 2 b ) 2 + k , {\displaystyle x^{2}+bx+c\,=\,\left(x+{\tfrac {1}{2}}b\right)^{2}+k,} where k = c b 2 4 {\displaystyle k=c-{\frac {b^{2}}{4}}} . This operation is known as completing the square. For example: x 2 + 6 x + 11 = ( x + 3 ) 2 + 2 x 2 + 14 x + 30 = ( x + 7 ) 2 19 x 2 2 x + 7 = ( x 1 ) 2 + 6. {\displaystyle {\begin{alignedat}{1}x^{2}+6x+11\,&=\,(x+3)^{2}+2\\x^{2}+14x+30\,&=\,(x+7)^{2}-19\\x^{2}-2x+7\,&=\,(x-1)^{2}+6.\end{alignedat}}}

Non-monic case

Given a quadratic polynomial of the form a x 2 + b x + c {\displaystyle ax^{2}+bx+c} it is possible to factor out the coefficient a, and then complete the square for the resulting monic polynomial.

Example: 3 x 2 + 12 x + 27 = 3 [ x 2 + 4 x + 9 ] = 3 [ ( x + 2 ) 2 + 5 ] = 3 ( x + 2 ) 2 + 3 ( 5 ) = 3 ( x + 2 ) 2 + 15 {\displaystyle {\begin{aligned}3x^{2}+12x+27&=3\\&{}=3\left\\&{}=3(x+2)^{2}+3(5)\\&{}=3(x+2)^{2}+15\end{aligned}}} This process of factoring out the coefficient a can further be simplified by only factorising it out of the first 2 terms. The integer at the end of the polynomial does not have to be included.

Example: 3 x 2 + 12 x + 27 = 3 [ x 2 + 4 x ] + 27 = 3 [ ( x + 2 ) 2 4 ] + 27 = 3 ( x + 2 ) 2 + 3 ( 4 ) + 27 = 3 ( x + 2 ) 2 12 + 27 = 3 ( x + 2 ) 2 + 15 {\displaystyle {\begin{aligned}3x^{2}+12x+27&=3\left+27\\&{}=3\left+27\\&{}=3(x+2)^{2}+3(-4)+27\\&{}=3(x+2)^{2}-12+27\\&{}=3(x+2)^{2}+15\end{aligned}}}

This allows the writing of any quadratic polynomial in the form a ( x h ) 2 + k . {\displaystyle a(x-h)^{2}+k.}

Formula

Scalar case

The result of completing the square may be written as a formula. In the general case, one has a x 2 + b x + c = a ( x h ) 2 + k , {\displaystyle ax^{2}+bx+c=a(x-h)^{2}+k,} with h = b 2 a and k = c a h 2 = c b 2 4 a . {\displaystyle h=-{\frac {b}{2a}}\quad {\text{and}}\quad k=c-ah^{2}=c-{\frac {b^{2}}{4a}}.}

In particular, when a = 1, one has x 2 + b x + c = ( x h ) 2 + k , {\displaystyle x^{2}+bx+c=(x-h)^{2}+k,} with h = b 2 and k = c h 2 = c b 2 4 . {\displaystyle h=-{\frac {b}{2}}\quad {\text{and}}\quad k=c-h^{2}=c-{\frac {b^{2}}{4}}.}

By solving the equation a ( x h ) 2 + k = 0 {\displaystyle a(x-h)^{2}+k=0} in terms of x h , {\displaystyle x-h,} and reorganizing the resulting expression, one gets the quadratic formula for the roots of the quadratic equation: x = b ± b 2 4 a c 2 a . {\displaystyle x={\frac {-b\pm {\sqrt {b^{2}-4ac}}}{2a}}.}

Matrix case

The matrix case looks very similar: x T A x + x T b + c = ( x h ) T A ( x h ) + k {\displaystyle x^{\mathrm {T} }Ax+x^{\mathrm {T} }b+c=(x-h)^{\mathrm {T} }A(x-h)+k} where h = 1 2 A 1 b {\textstyle h=-{\frac {1}{2}}A^{-1}b} and k = c 1 4 b T A 1 b {\textstyle k=c-{\frac {1}{4}}b^{\mathrm {T} }A^{-1}b} . Note that A {\displaystyle A} has to be symmetric.

If A {\displaystyle A} is not symmetric the formulae for h {\displaystyle h} and k {\displaystyle k} have to be generalized to: h = ( A + A T ) 1 b and k = c h T A h = c b T ( A + A T ) 1 A ( A + A T ) 1 b {\displaystyle h=-(A+A^{\mathrm {T} })^{-1}b\quad {\text{and}}\quad k=c-h^{\mathrm {T} }Ah=c-b^{\mathrm {T} }(A+A^{\mathrm {T} })^{-1}A(A+A^{\mathrm {T} })^{-1}b}

Relation to the graph

Graphs of quadratic functions shifted to the right by h = 0, 5, 10, and 15.Graphs of quadratic functions shifted to the right by h = 0, 5, 10, and 15.Graphs of quadratic functions shifted upward by k = 0, 5, 10, and 15.Graphs of quadratic functions shifted upward by k = 0, 5, 10, and 15.Graphs of quadratic functions shifted upward and to the right by 0, 5, 10, and 15.Graphs of quadratic functions shifted upward and to the right by 0, 5, 10, and 15.

In analytic geometry, the graph of any quadratic function is a parabola in the xy-plane. Given a quadratic polynomial of the form a ( x h ) 2 + k {\displaystyle a(x-h)^{2}+k} the numbers h and k may be interpreted as the Cartesian coordinates of the vertex (or stationary point) of the parabola. That is, h is the x-coordinate of the axis of symmetry (i.e. the axis of symmetry has equation x = h), and k is the minimum value (or maximum value, if a < 0) of the quadratic function.

One way to see this is to note that the graph of the function f(x) = x is a parabola whose vertex is at the origin (0, 0). Therefore, the graph of the function f(xh) = (xh) is a parabola shifted to the right by h whose vertex is at (h, 0), as shown in the top figure. In contrast, the graph of the function f(x) + k = x + k is a parabola shifted upward by k whose vertex is at (0, k), as shown in the center figure. Combining both horizontal and vertical shifts yields f(xh) + k = (xh) + k is a parabola shifted to the right by h and upward by k whose vertex is at (h, k), as shown in the bottom figure.

Solving quadratic equations

Completing the square may be used to solve any quadratic equation. For example: x 2 + 6 x + 5 = 0. {\displaystyle x^{2}+6x+5=0.}

The first step is to complete the square: ( x + 3 ) 2 4 = 0. {\displaystyle (x+3)^{2}-4=0.}

Next we solve for the squared term: ( x + 3 ) 2 = 4. {\displaystyle (x+3)^{2}=4.}

Then either x + 3 = 2 or x + 3 = 2 , {\displaystyle x+3=-2\quad {\text{or}}\quad x+3=2,} and therefore x = 5 or x = 1. {\displaystyle x=-5\quad {\text{or}}\quad x=-1.}

This can be applied to any quadratic equation. When the x has a coefficient other than 1, the first step is to divide out the equation by this coefficient: for an example see the non-monic case below.

Irrational and complex roots

Unlike methods involving factoring the equation, which is reliable only if the roots are rational, completing the square will find the roots of a quadratic equation even when those roots are irrational or complex. For example, consider the equation x 2 10 x + 18 = 0. {\displaystyle x^{2}-10x+18=0.}

Completing the square gives ( x 5 ) 2 7 = 0 , {\displaystyle (x-5)^{2}-7=0,} so ( x 5 ) 2 = 7. {\displaystyle (x-5)^{2}=7.} Then either x 5 = 7 or x 5 = 7 . {\displaystyle x-5=-{\sqrt {7}}\quad {\text{or}}\quad x-5={\sqrt {7}}.}

In terser language: x 5 = ± 7 , {\displaystyle x-5=\pm {\sqrt {7}},} so x = 5 ± 7 . {\displaystyle x=5\pm {\sqrt {7}}.}

Equations with complex roots can be handled in the same way. For example: x 2 + 4 x + 5 = 0 ( x + 2 ) 2 + 1 = 0 ( x + 2 ) 2 = 1 x + 2 = ± i x = 2 ± i . {\displaystyle {\begin{aligned}x^{2}+4x+5&=0\\(x+2)^{2}+1&=0\\(x+2)^{2}&=-1\\x+2&=\pm i\\x&=-2\pm i.\end{aligned}}}

Non-monic case

For an equation involving a non-monic quadratic, the first step to solving them is to divide through by the coefficient of x. For example:

2 x 2 + 7 x + 6 = 0 x 2 + 7 2 x + 3 = 0 ( x + 7 4 ) 2 1 16 = 0 ( x + 7 4 ) 2 = 1 16 x + 7 4 = 1 4 or x + 7 4 = 1 4 x = 3 2 or x = 2. {\displaystyle {\begin{array}{c}2x^{2}+7x+6\,=\,0\\x^{2}+{\tfrac {7}{2}}x+3\,=\,0\\\left(x+{\tfrac {7}{4}}\right)^{2}-{\tfrac {1}{16}}\,=\,0\\\left(x+{\tfrac {7}{4}}\right)^{2}\,=\,{\tfrac {1}{16}}\\x+{\tfrac {7}{4}}={\tfrac {1}{4}}\quad {\text{or}}\quad x+{\tfrac {7}{4}}=-{\tfrac {1}{4}}\\x=-{\tfrac {3}{2}}\quad {\text{or}}\quad x=-2.\end{array}}}

Applying this procedure to the general form of a quadratic equation leads to the quadratic formula.

Other applications

Integration

Completing the square may be used to evaluate any integral of the form d x a x 2 + b x + c {\displaystyle \int {\frac {dx}{ax^{2}+bx+c}}} using the basic integrals d x x 2 a 2 = 1 2 a ln | x a x + a | + C and d x x 2 + a 2 = 1 a arctan ( x a ) + C . {\displaystyle \int {\frac {dx}{x^{2}-a^{2}}}={\frac {1}{2a}}\ln \left|{\frac {x-a}{x+a}}\right|+C\quad {\text{and}}\quad \int {\frac {dx}{x^{2}+a^{2}}}={\frac {1}{a}}\arctan \left({\frac {x}{a}}\right)+C.}

For example, consider the integral d x x 2 + 6 x + 13 . {\displaystyle \int {\frac {dx}{x^{2}+6x+13}}.}

Completing the square in the denominator gives: d x ( x + 3 ) 2 + 4 = d x ( x + 3 ) 2 + 2 2 . {\displaystyle \int {\frac {dx}{(x+3)^{2}+4}}\,=\,\int {\frac {dx}{(x+3)^{2}+2^{2}}}.}

This can now be evaluated by using the substitution u = x + 3, which yields d x ( x + 3 ) 2 + 4 = 1 2 arctan ( x + 3 2 ) + C . {\displaystyle \int {\frac {dx}{(x+3)^{2}+4}}\,=\,{\frac {1}{2}}\arctan \left({\frac {x+3}{2}}\right)+C.}

Complex numbers

Consider the expression | z | 2 b z b z + c , {\displaystyle |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| = uu we can rewrite this as | z b | 2 | b | 2 + c , {\displaystyle |z-b|^{2}-|b|^{2}+c,} which is clearly a real quantity. This is because | z b | 2 = ( z b ) ( z b ) = ( z b ) ( z b ) = z z z b b z + b b = | z | 2 z b b z + | b | 2 . {\displaystyle {\begin{aligned}|z-b|^{2}&{}=(z-b)(z-b)^{*}\\&{}=(z-b)(z^{*}-b^{*})\\&{}=zz^{*}-zb^{*}-bz^{*}+bb^{*}\\&{}=|z|^{2}-zb^{*}-bz^{*}+|b|^{2}.\end{aligned}}}

As another example, the expression a x 2 + b y 2 + c , {\displaystyle ax^{2}+by^{2}+c,} where a, b, c, x, and y are real numbers, with a > 0 and b > 0, may be expressed in terms of the square of the absolute value of a complex number. Define z = a x + i b y . {\displaystyle z={\sqrt {a}}\,x+i{\sqrt {b}}\,y.}

Then | z | 2 = z z = ( a x + i b y ) ( a x i b y ) = a x 2 i a b x y + i b a y x i 2 b y 2 = a x 2 + b y 2 , {\displaystyle {\begin{aligned}|z|^{2}&{}=zz^{*}\\&{}=\left({\sqrt {a}}\,x+i{\sqrt {b}}\,y\right)\left({\sqrt {a}}\,x-i{\sqrt {b}}\,y\right)\\&{}=ax^{2}-i{\sqrt {ab}}\,xy+i{\sqrt {ba}}\,yx-i^{2}by^{2}\\&{}=ax^{2}+by^{2},\end{aligned}}} so a x 2 + b y 2 + c = | z | 2 + c . {\displaystyle ax^{2}+by^{2}+c=|z|^{2}+c.}

Idempotent matrix

A matrix M is idempotent when M = M. Idempotent matrices generalize the idempotent properties of 0 and 1. The completion of the square method of addressing the equation a 2 + b 2 = a , {\displaystyle a^{2}+b^{2}=a,} shows that some idempotent 2×2 matrices are parametrized by a circle in the (a,b)-plane:

The matrix ( a b b 1 a ) {\displaystyle {\begin{pmatrix}a&b\\b&1-a\end{pmatrix}}} will be idempotent provided a 2 + b 2 = a , {\displaystyle a^{2}+b^{2}=a,} which, upon completing the square, becomes ( a 1 2 ) 2 + b 2 = 1 4 . {\displaystyle (a-{\tfrac {1}{2}})^{2}+b^{2}={\tfrac {1}{4}}.} In the (a,b)-plane, this is the equation of a circle with center (1/2, 0) and radius 1/2.

Geometric perspective

Consider completing the square for the equation x 2 + b x = a . {\displaystyle x^{2}+bx=a.}

Since x 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 x and the bx rectangles into a larger square result in a missing corner. The term (b/2) added to each side of the above equation is precisely the area of the missing corner, whence derives the terminology "completing the square".

A variation on the technique

As conventionally taught, completing the square consists of adding the third term, v to u 2 + 2 u v {\displaystyle u^{2}+2uv} to get a square. There are also cases in which one can add the middle term, either 2uv or −2uv, to u 2 + v 2 {\displaystyle u^{2}+v^{2}} to get a square.

Example: the sum of a positive number and its reciprocal

By writing x + 1 x = ( x 2 + 1 x ) + 2 = ( x 1 x ) 2 + 2 {\displaystyle {\begin{aligned}x+{1 \over x}&{}=\left(x-2+{1 \over x}\right)+2\\&{}=\left({\sqrt {x}}-{1 \over {\sqrt {x}}}\right)^{2}+2\end{aligned}}} 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. {\displaystyle x^{4}+324.}

This is ( x 2 ) 2 + ( 18 ) 2 , {\displaystyle (x^{2})^{2}+(18)^{2},} so the middle term is 2(x)(18) = 36x. Thus we get x 4 + 324 = ( x 4 + 36 x 2 + 324 ) 36 x 2 = ( x 2 + 18 ) 2 ( 6 x ) 2 = a difference of two squares = ( x 2 + 18 + 6 x ) ( x 2 + 18 6 x ) = ( x 2 + 6 x + 18 ) ( x 2 6 x + 18 ) {\displaystyle {\begin{aligned}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{aligned}}} (the last line being added merely to follow the convention of decreasing degrees of terms).

The same argument shows that x 4 + 4 a 4 {\displaystyle x^{4}+4a^{4}} is always factorizable as x 4 + 4 a 4 = ( x 2 + 2 a x + 2 a 2 ) ( x 2 2 a x + 2 a 2 ) {\displaystyle x^{4}+4a^{4}=\left(x^{2}+2ax+2a^{2}\right)\left(x^{2}-2ax+2a^{2}\right)} (Also known as Sophie Germain's identity).

Completing the cube

"Completing the square" consists to remark that the two first terms of a quadratic polynomial are also the first terms of the square of a linear polynomial, and to use this for expressing the quadratic polynomial as the sum of a square and a constant.

Completing the cube is a similar technique that allows to transform a cubic polynomial into a cubic polynomial without term of degree two.

More precisely, if

a x 3 + b x 2 + c x + d {\displaystyle ax^{3}+bx^{2}+cx+d}

is a polynomial in x such that a 0 , {\displaystyle a\neq 0,} its two first terms are the two first terms of the expanded form of

a ( x + b 3 a ) 3 = a x 3 + b x 2 + x b 2 3 a + b 3 27 a 2 . {\displaystyle a\left(x+{\frac {b}{3a}}\right)^{3}=ax^{3}+bx^{2}+x\,{\frac {b^{2}}{3a}}+{\frac {b^{3}}{27a^{2}}}.}

So, the change of variable

t = x + b 3 a {\displaystyle t=x+{\frac {b}{3a}}}

provides a cubic polynomial in t {\displaystyle t} without term of degree two, which is called the depressed form of the original polynomial.

This transformation is generally the first step of the methods for solving the general cubic equation.

More generally, a similar transformation can be used for removing terms of degree n 1 {\displaystyle n-1} in polynomials of degree n {\displaystyle n} , which is called Tschirnhaus transformation.

References

  1. Anita Wah; Creative Publications, Inc (1994). Algebra: Themes, Tools, Concepts. Henri Picciotto. p. 500. ISBN 978-1-56107-251-4. Extract of page 500 Chris Kornegay (1999). Math Dictionary With Solutions. SAGE. p. 373. ISBN 978-0-7619-1785-4. Extract of page 373 The form a ( x + h ) 2 + k {\displaystyle a(x+h)^{2}+k} is also sometimes used. Karen Morrison; Nick Hamshaw (2018). Cambridge IGCSE® Mathematics Core and Extended Coursebook (illustrated, revised ed.). Cambridge University Press. p. 322. ISBN 978-1-108-43718-9. Extract of page 322 Shefiu Zakariyah (2024). Foundation Mathematics for Engineers and Scientists with Worked Examples. Taylor & Francis. p. 254. ISBN 978-1-003-85984-0. Extract of page 254
  2. Dionissios T. Hristopulos (2020). Random Fields for Spatial Data Modeling: A Primer for Scientists and Engineers. Springer Nature. p. 267. ISBN 978-94-024-1918-4. Extract of page 267
  3. James R. Brannan; William E. Boyce (2015). Differential Equations: An Introduction to Modern Methods and Applications (3rd ed.). John Wiley & Sons. p. 314. ISBN 978-1-118-98122-1. Extract of page 314
  4. Stephen L. Campbell; Richard Haberman (2011). Introduction to Differential Equations with Dynamical Systems (illustrated ed.). Princeton University Press. p. 214. ISBN 978-1-4008-4132-5. Extract of page 214
  5. Tony Philips, "Completing the Square", American Mathematical Society Feature Column, 2020.
  6. Hughes, Barnabas. "Completing the Square - Quadratics Using Addition". Math Association of America. Retrieved 2022-10-21.
  7. Narasimhan, Revathi (2008). Precalculus: Building Concepts and Connections. Cengage Learning. pp. 133–134. ISBN 978-0-618-41301-0., Section Formula for the Vertex of a Quadratic Function, page 133–134, figure 2.4.8
  8. Carroll, Maureen T.; Rykken, Elyn (2018). Geometry: The Line and the Circle. AMS/MAA Textbooks. American Mathematical Society. p. 162. ISBN 978-1-4704-4843-1. Retrieved 2024-03-31.

External links

Category: