# Completing the Square - Multiple Variables

Completing the square of an expression with multiple variables is a technique which manipulates the expression into a perfect square plus some constant. As an example, \(x^2+2x+y^2-6y+z^2 - 8z + 1\) can be written in the complete square form as \[(x+1)^2+(y-3)^2+(z-4)^2-25.\]

This technique is useful in factorizing an expression, dealing with the conic sections, finding the maxima and minima of an expression.

#### Contents

## Introduction

Let us look at how \(x^2+y^2+z^2+2x-6y-8z + 1\) can be split into squares.

Firstly, notice that the expression does not have any product terms such as \(xy\) or \(yz\). This means that we could split this into squares of single variable polynomials,i.e, something like \[(Ax + a)^2 + (By + b)^2 + (Cz + c)^2 + d^2 \]

The key in such cases is to complete the square for each variable separately and combine them.Let us deal with \(x\): \[x^2 + 2x = (x + 1)^2 - 1\] and \(y\): \[y^2 - 6y = (y - 3)^2 - 9\] and \(z\): \[z^2 - 8z = (z - 4)^2 - 16\]

Now, the original polynomial could be written as

\[ \left \{ (x + 1)^2 - 1 \right \} + \left \{ (y - 3)^2 - 9 \right \} + \left \{ (z - 4)^2 - 16 \right \} + 1 \\ = (x+1)^2 + (y-3)^2 + (z-4)^2 - 25 = (x+1)^2 + (y-3)^2 + (z-4)^2 - 5^2 \]

What if there are product terms? In that case, *we guess which variables needed to be together in order to make the product term and manipulate accordingly*.

Express \(x^2 + 13y^2 + z^2 + 6 x y + 4 y z\) as a sum of squares.

Here the product terms contain \(xy\) and \(yz\). We could hope to possibly rewrite the polynomial as something like \[(Ax + By + C)^2 + (Py + Qz + R)^2\]

As for the terms with \(x\) and \(y\), we have \[x^2 + 6 x y + 13 y^2 = (x + 3y)^2 + (2y)^2\]

And for the terms with \(y\) and \(z\), we have \[13y^2 + 4 y z + z^2 = (z + 2y)^2 + (3y)^2\]

And we add them up, and subtract \(13y^2\), as we are double counting it, to write the original polynomial as \[ \left \{ (x + 3y)^2 + (2y)^2 \right \}+ \left \{ (z + 2y)^2 + (3y)^2 \right \} - 13y^2 = (x + 3y)^2 + (2y + z)^2 \]

## Application - Factorization

Solve for \( x \) in \( ax^2 + bx + c = 0 \), where \( a, b, c \in \mathbb{R} \).

Solution:We can use completing the square method.

\[ x^2 + \dfrac{b}{a} x + \dfrac{c}{a} = 0 \]

What must we add so that we have a perfect square? \( \dfrac{b}{a}x = 2xz \) and a perfect square would be in the form \( x^2 + 2xz + z^2 \) so we need to find \( z \) and square it. \( z = \dfrac{b}{2a}; z^2 = \dfrac{b^2}{4a^2} \). We add \( z^2 \) to both sides.

\[ x^2 + \dfrac{b}{a}x + \dfrac{b^2}{4a^2} + \dfrac{c}{a} = \dfrac{b^2}{4a^2} \]

\[ \left( x + \dfrac{b}{2a}\right)^2 = \dfrac{-c}{a} + \dfrac{b^2}{4a^2} \]

\[ \left( x + \dfrac{b}{2a} \right)^2 = \dfrac{b^2 -4ac}{4a^2} \]

\[ x + \dfrac{b}{2a} = \pm \sqrt{\dfrac{b^2 - 4ac}{4a^2 }} = \pm \dfrac{\sqrt{b^2 - 4ac}}{2a} \]

\[ x = \boxed{ \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a } }\]

Factor \( x^4 + x^2 y^2 + y^4 \).

Solution:This seems unfactorable but we can make it factorable by adding and subtracting \( x^2 y^2 \).

\[ = x^4 + 2x^2 y^2 + y^4 - x^2 y^2 \]

We now have a perfect square.

\[ = (x^2 + y^2)^2 - x^2 y^2 \]

We now have a difference of two squares.

\[ = \boxed{ (x^2 + y^2 + xy)(x^2 + y^2 - xy) } \]

Factor \(x^4+4y^4\).

Solution:Again, we can complete the square by adding and subtracting the middle term \(4x^2y^2\):

\[\begin{align} &=x^4\color{red}{+4x^2y^2}+4y^4\color{red}{-4x^2y^2} \\ &=(x^2+2y^2)^2-4x^2y^2 \end{align} \]

We now have a difference of two squares:

\[=\boxed{(x^2+2xy+2y^2)(x^2-2xy+2y^2)}\]

This result is best know as

Sophie Germain Identity.

## Application - Conic Sections

For a general conic \(ax^2+cy^2+dx+ey+f=0\) we can complete the square to find all of its elements. Let's begin identifying the conics:

- When \(ac>0\) we have an
**ellipse**(\(a\) and \(c\) have the same sign but \(a \neq c\)). - When \(a=c\) and \(a,c \neq 0\) we have a
**circle**. - When \(ac<0\) we have an
**hyperbola**(\(a\) and \(c\) have different sign). - When \(ac=0\) we have a
**parabola**(only one of \(a\) and \(c\) is zero).

For each one we have different forms and elements:

A

circlewith center in \(C=(h,k)\) and radius \(r\) has the equation: \[(x-h)^2+(y-k)^2=r^2\]

**Strategies for completing the square - Circles**:

- Move all terms containing \(x\) and \(y\) to one side, and the constant term (if there is) to the other side.
- Divide the equation by the coefficient of \(x\) and \(y\) if it's different from one.
- Complete the square in \(x\) and \(y\).
- Rearrange and identify its elements.

Identify all the elements of the conic \(x^2+y^2-6x+14y+42=0\).

Solution:Since the coefficients of \(x^2\) and \(y^2\) are \(1\) we have a circle, so we are looking for its center and radius. We move the constant term \(42\) to the other side:

\[x^2+y^2-6x+14y=\color{green}{-42}\]

Now, we complete the square in \(x\) and \(y\):

\[x^2-6x+\color{red}{9}+y^2+14y+\color{blue}{49}=-42+\color{red}{9}+\color{blue}{49}\]

Finally, we rearrange:

\[(x-3)^2+(y+7)^2=16\]

Comparing with the equation of the circle, we find \(C=(3,-7)\) and \(r=\sqrt{16}=4\). \(\square\)

An

ellipsewith center in \(C=(h,k)\), semi-major axis \(a\) and semi-minor axis \(b\) has the equations:

- Horizontal ellipse: \[\dfrac{(x-h)^2}{a^2}+\dfrac{(y-k)^2}{b^2}=1\]
- Vertical ellipse: \[\dfrac{(y-k)^2}{a^2}+\dfrac{(x-h)^2}{b^2}=1\]

**Strategies for completing the square - Ellipses**:

- Move all terms containing \(x\) and \(y\) to one side, and the constant term (if there is) to the other side.
- Factorize the \(x^2\) and the \(x\) term by common factor, using such factor as the coefficient of \(x^2\).
- Do the same with \(y^2\) and \(y\).
- Complete the square in \(x\) and \(y\).
- Simplify both sides.
- Divide both sides by the term in the right side.
- Simplify the fractions.
- Identify all the elements.

Identify all the elements of the conic \(9x^2+25y^2+36x-50y-164=0\).

Solution:Since the coefficients of \(x^2\) and \(y^2\) are different but have the same sign, we have an ellipse. First we move the constant term to the right side:

\[9x^2+25y^2+36x-50y=\color{green}{164}\]

Next, we factorize the \(x^2\) and the \(x\) terms. We see that the coefficient of \(x^2\) is \(9\), so it will be the common factor. We will have to divide the coefficient of \(x\), which is \(36\) by \(9\). We also do the same with \(y^2\) and \(y\):

\[\color{red}{9(x^2+4x)}+\color{blue}{25(y^2-2y)}=164\]

Now we complete the square, without forgetting to multiply the terms that we will add on the right side by \(9\) and \(25\):

\[9(x^2+4x+\color{red}{4})+25(y^2-2y+\color{blue}{1})=164+\color{red}{9(4)}+\color{blue}{25(1)}\]

Simplify:

\[9(x+2)^2+25(y-1)^2=225\]

Divide both sides by \(225\):

\[\dfrac{9(x+2)^2}{\color{green}{225}}+\dfrac{25(y-1)^2}{\color{green}{225}}=1\]

Finally simplify the fractions to obtain the form of the equation of the ellipse:

\[\dfrac{(x+2)^2}{25}+\dfrac{(y-1)^2}{9}=1\]

Since \(25>9\) we have an horizontal ellipse with \(a=\sqrt{25}=5\), \(b=\sqrt{9}=3\) and center in \(C=(-2,1)\). \(\square\)

An

hyperbolawith center in \(C=(h,k)\), semi-major axis \(a\) and semi-minor axis \(b\) has the equations:

- Horizontal hyperbola: \[\dfrac{(x-h)^2}{a^2}-\dfrac{(y-k)^2}{b^2}=1\]
- Vertical hyperbola: \[\dfrac{(y-k)^2}{a^2}-\dfrac{(x-h)^2}{b^2}=1\]

**Strategies for completing the square - Hyperbola**:

The steps are almost the same than those of the ellipse, but we have to be more careful with the signs.

Identify all elements of the conic \(7x^2-10y^2+70x+80y-55=0\).

Solution:Since the coefficients of \(x^2\) and \(y^2\) have different signs, we have an hyperbola. First we move the constant term to the right side:

\[7x^2-10y^2+70x+80y=\color{green}{55}\]

Next, we factorize the \(x^2\) and the \(x\) terms. We see that the coefficient of \(x^2\) is \(7\), so it will be the common factor. We will have to divide the coefficient of \(x\), which is \(70\) by \(7\):

\[\color{red}{7(x^2+10x)}-10y^2+80y=55\]

Do the same with \(y^2\) and \(y\). We see that the coefficient of \(y^2\) is \(-10\), so that will be the common factor. We will have to divide the coefficient of \(y\), which is \(80\) by \(-10\):

\[7(x^2+10x)\color{blue}{-10(y^2-8y)}=55\]

Now we complete the square, without forgetting to multiply the terms that we will add on the right side by \(7\) and \(-10\):

\[7(x^2+10x+\color{red}{25})-10(y^2-8y+\color{blue}{16})=55\color{red}{+7(25)}\color{blue}{-10(16)}\]

Simplify:

\[7(x+5)^2-10(y-4)^2=70\]

Divide both sides by \(70\):

\[\dfrac{7(x+5)^2}{\color{green}{70}}-\dfrac{10(y-4)^2}{\color{green}{70}}=1\]

Finally simplify the fractions to obtain the form of the equation of the hyperbola:

\[\dfrac{(x+5)^2}{10}-\dfrac{(y-4)^2}{7}=1\]

We have an horizontal hyperbola with \(a=\sqrt{10}\), \(b=\sqrt{7}\) and center in \(C=(-5,4)\). \(\square\)

A

parabolawith vertex in \(V=(h,k)\) and focal distance \(p\) has the equations:

- Horizontal parabola. If \(p>0\) the parabola is directed to the right, if \(p<0\) it's directed to the left: \[(y-k)^2=4p(x-h)\]
- Vertical parabola. If \(p>0\) the parabola is directed upwards, if \(p<0\) it's directed downwards: \[(x-h)^2=4p(y-k)\]

**Strategies for completing the square - Parabola**:

- Identify the variable that is squared. Factorize it with the linear one by common factor, using such factor as the coefficient of the squared variable.
- Complete the square in the squared variable.
- Move the constant terms and the terms with the variable that is not squared to the right side.
- Factorize the right side again using common factor, using such factor as the coefficient of the linear variable.
- Divide both sides by the coefficient of the squared binom on the left side.
- Identify all the elements.

Identify all elements of the conic \(3x^2-30x-20y+235=0\).

Solution:Since we have an \(x^2\) term but no \(y^2\) term, we have a parabola. First we will factorize the \(x^2\) and the \(x\) terms. We see that the coefficient of \(x^2\) is \(3\), so it will be the common factor:

\[\color{red}{3(x^2-10x)}-20y+235=0\]

Next, we will complete the square in \(x\), without forgetting to multiply the term that we will add on the right side by \(3\):

\[3(x^2-10x+\color{red}{25})-20y+235=\color{red}{3(25)}\]

Next, we will move the \(y\) and the constant term to the other side, and simplify:

\[3(x-5)^2=\color{green}{20y-235}+\color{red}{75}\] \[3(x-5)^2=20y-160\]

Factorize the right side. We see that the coefficient of \(y\) is \(20\), so it will be the common factor:

\[3(x-5)^2=\color{blue}{20(y-8)}\]

Divide both sides by \(3\):

\[(x-5)^2=\color{green}{\dfrac{20}{3}}(y-8)\]

We have a vertical parabola which opens upwards. It has vertex in \(V=(5,8)\) and its focal distance is \(4p=20/3 \implies p=5/3\). \(\square\)

## Application - Quadric Surfaces

We can also have "3-dimensional conic sections", referred to as **quadric surfaces**.
Given an equation in terms of \( x, y, z \), we can use multivariable completing the square to identify certain characteristics of these quadric surfaces.

An

ellipsoidhas the equation \( \dfrac{(x-h)^2}{a^2} + \dfrac{(y-k)^2}{b^2} + \dfrac{(z-l)^2}{c^2} = 1 \).All traces are

ellipses. (Atraceis the equation of intersection between a plane and the given surface).Its center is at \( (h, k, l ) \).

If \( a = b = c\), then the ellipsoid is a sphere.

Ellipsoids have 3 axes of symmetry, namely:

\( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \) , \( \left\{\begin{matrix} x= h\\ y=t-k\\ z=l \end{matrix}\right. \) , and \( \left\{\begin{matrix} x= t-h\\ y=k\\ \\ z=l \end{matrix}\right. \)

An

elliptic paraboloidhas the equation \( \dfrac{z-l}{c} = \dfrac{(x-h)^2}{a^2} + \dfrac{(y-k)^2}{b^2} \).The vertex of the elliptic paraboloid is at \( (h, k, l ) \). Conceptually, this is similar to the vertex-form of a parabola in 2D.

Horizontal traces are ellipses, and vertical traces are parabolas.

The axis of symmetry is \( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \)

A

hyperbolic paraboloid, or commonly known as Pringles chip, has the equation \( \dfrac{z-l}{c} = \dfrac{(x-h)^2}{a^2} - \dfrac{(y-k)^2}{b^2} \).The center of the hyperbolic paraboloid (in this case, the

saddle point, where the partial derivatives in all directions equal zero, but this point is neither a maximum nor a minimum) is \( (h, k, l) \).

The axis of symmetry is \( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \)

An

elliptical conehas the equation \( \dfrac{(z-l)^2}{c^2} = \dfrac{(x-h)^2}{a^2} + \dfrac{(y-k)^2}{b^2} \).The "center" is located at \( (h, k, l) \).

Horizontal traces are ellipses, and vertical traces are hyperbolas or lines, depending on the equation of the plane.

The axis of symmetry is \( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \)

A

hyperboloid of one sheetlooks like a nuclear cooling tower and has the equation \( 1 = \dfrac{(x-h)^2}{a^2} + \dfrac{(y-k)^2}{b^2} - \dfrac{(z-l)^2}{c^2} \).The "center" is located at \( (h, k, l) \).

Horizontal traces are ellipses, and vertical traces are hyperbolas.

The axis of symmetry is \( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \)

A

hyperboloid of two sheetslooks like two mirrored elliptic paraboloids and has the equation \( 1 = -\dfrac{(x-h)^2}{a^2} - \dfrac{(y-k)^2}{b^2} + \dfrac{(z-l)^2}{c^2} \).The two sheets are "mirrored" around \( (h, k, l ) \).

Horizontal traces when the plane is parallel to the \( z\) axis are ellipses when the plane intersects one of the two sheets. Vertical traces are hyperbolas.

The axis of symmetry is \( \left\{\begin{matrix} x= h\\ y=k\\ z=t-l \end{matrix}\right. \)

Identify the quadric surface and its elements:

\[ 4604 = 400x^2 - 800x + 225y^2 + 900y - 144z^2 - 1152 z \]

Solution:\[ 4604 + 400 + 900 - 2304 = 400x^2 - 800x + 400 + 225y^2 + 900y + 900 - 144z^2 - 1152z -2304 \]

\[ 3600 = 400(x-1)^2 + 225(y+2)^2 - 144(z+4)^2 \]

\[ 1 = \dfrac{(x-1)^2}{3^2} + \dfrac{(y+2)^2}{4^2} - \dfrac{(z+4)^2}{5^2} \]

We can see that the equation is a \( \boxed{\text{hyperboloid of one sheet}} \). Its center is at \( (1, -2, -4 ) \). Its axis of symmetry is \( \left\{\begin{matrix} x= 1\\ y=-2\\ z=t+4 \end{matrix}\right.\).

## Applications - Extrema Values

When relating squares and inequality, one should be reminded of the Trivial Inequality :

For any real number \(x\), we have

\[x^2 \geq 0\]

and equality holds if and only if \(x=0\).

Let's look at a simple example.

For real number \(x\) and \(y\), what is the minimum value of \( z = x^2 -2x + y^2 + 4y \)?

In this expression we have to deal with two variables. It is hard at first how to approach or even predict the minimum value. Let's try reducing the number of terms by completing the square

\[\begin{aligned} z &= x^2 -2x + y^2 + 4y \\ &= (x^2 -2x +1 ) - 1 + (y^2 + 4y +4) - 4 \\ &= (x -1 )^2 + (y +2)^2 - 5 \end{aligned}\]

The minimum value of a square is \(0\), hence the minimum value of \(z\) is \(0+0-5=-5\) and the equality holds when \(x=1\) and \(y=-2\).

Now, let's try a slightly more difficult question when there are more terms.

\[f(x,y,z)=2x^2+8y^2+9z^2+4xy-12yz+2x-6\]

The function above has a minimum value for real number \(x,y,z\). Find the minimum value, and state the ordered triplet \((x,y,z)\) where the minimum occurs.

Notice that there are product terms \(xy\) and \(yz\). We can try to factorize these first. Notice that \(y\) appears in both products, and \(x\) has a term by itself. Therefore, we can start by attempting to factorize \(z\). Notice that

\(9z^2 = (3z)^2\\ 12yz = 2(3z)(2y)\)

From here, we can see that we already have most of the required terms to complete the square. What we're missing is \((2y)^2=4y^2\), and we try to obtain the term:

\[\begin{aligned} f(x,y,z)&=2x^2\color{blue}{+8y^2}+9z^2+4xy-12yz+2x-6\\ &=2x^2+4xy+2x-6\color{blue}{+4y^2+4y^2} -12yz+9z^2\\ &=2x^2+4xy+2x-6+4y^2+(2y-3z)^2\end{aligned}\]

Next, we try to do the same thing for \(xy\). Notice that

\(4y^2=(2y)^2\\ 4xy=2(2y)(x)\)

What we need is a \(x^2\):

\[\begin{aligned} f(x,y,z)&=\color{red}{2x^2}+4xy+2x-6+4y^2+(2y-3z)^2\\ &=2x-6\color{red}{+x^2+x^2}+4xy+4y^2+(2y-3z)^2\\ &=x^2+2x+1-1-6+(x+2y)^2+(2y-3z)^2\\ &=(x+1)^2+(x+2y)^2+(2y-3z)^2-7\end{aligned}\]

All the variables have been placed in squares. Now, the function will be minimized if all 3 squares equal to \(0\). Therefore, we need to find out if we can get all 3 squares to be \(0\):

\(x+1=0\implies x=-1\\ x+2y=0 \implies y=-\dfrac{x}{2}=\dfrac{1}{2}\\ 2y-3z=0 \implies z=\dfrac{2y}{3}=\dfrac{1}{3}\)

We see that it is indeed achievable. Therefore, we get our answer: \(\boxed{f_{\text{min}}(x,y,z)=-7}\) when \(\boxed{(x,y,z)=\left(-1,\dfrac{1}{2},\dfrac{1}{3}\right)}\)

## Problem Solving

We will work through several problems to gain a stronger understanding on the usefulness of completing the square.

Prove that there are no integer solution for the equation

\[x^2+2x+y^2+2y+2xy-22=0\]

Factorize the expression we get

\[\begin{aligned} (x+y)^2+2(x+y)+1=23 \\ (x+y+1)^2=23 \end{aligned}\]

\(23\) is not a square, hence there are no integer \(x,y\) solution.

Factor \( x^3 + y^3 + z^3 - 3xyz \).

Solution:This isn't really completing the square, but rather completing the cube.

\[ =(x^3 + y^3) + z^3 - 3xyz \]

\[ =(x^3 + 3x^2 y + 3xy^2 + y^3) + z^3 - 3xyz - 3x^2 y - 3xy^2 \]

\[ =(x+y)^3 + z^3 - 3xyz - 3x^2 y - 3xy^2 \]

\[ =(x + y + z)[(x+y)^2 + z^2 - z(x+y) ] - 3xy(x+y+z) \]

\[= (x+y+z) [x^2 + y^2 + 2xy + z^2 - xz - yz - 3xy] \]

\[ = \boxed{ (x+y+z)[x^2 + y^2 + z^2 - xz - xy - yz] }\]

If \[ \Delta = \begin{vmatrix} a & b & c \\ b & c & a \\ c & a & b \end{vmatrix} = 0\]

and

\[ a \neq b \neq c \]

Find

\[ a + b + c \]

\[ \Delta = \begin{vmatrix} a & b & c \\ b & c & a \\ c & a & b \end{vmatrix} \]

Adding column 2 and column 3 to column 1, we have:

\[\Delta = \begin{vmatrix} a + b + c & b & c \\ b + c + a & c & a \\ c + a + b & a & b \end{vmatrix} \\ = (a + b + c) \begin{vmatrix} 1 & b & c \\ 1 & c & a \\ 1 & a & b \end{vmatrix}\]

Subtracting row 3 from row 1 and row 2:

\[ \Delta = (a + b + c) \begin{vmatrix} 0 & b-a & c-b \\ 0 & c-a & a-b \\ 1 & a & b \end{vmatrix} \]

Multiplying out:

\[\Delta = (a + b + c) \left \{ (c-a)(c-b) - (a-b)(b-a) \right \} \\ = (a + b + c) (c^2 - bc - ac + ab - ab + a^2 + b^2 - ab) \\ = (a + b + c) (a^2 + b^2 + c^2 - ab - bc - ca) \]

This is where completing the square comes in:

\[ \Delta = 0 \\ \implies (a + b + c) (a^2 + b^2 + c^2 - ab - bc - ca) = 0 \\ \implies (a + b + c) (2a^2 + 2b^2 + 2c^2 - 2ab - 2bc - 2ca) = 0 \\ \implies (a + b + c) \left \{ (a^2 - 2ab + b^2) + (b^2 - 2bc + c^2) + (c^2 - 2ac + c^2) \right \} = 0 \\ \implies (a + b + c) \left \{ (a - b)^2 + (b - c)^2 + (c - a)^2 \right \} = 0 \]

Now, \( \left \{ (a - b)^2 + (b - c)^2 + (c - a)^2 \right \} \) cannot be 0. If it were, that would imply \( a = b = c \).

Hence, \[ a + b + c = 0 \]

**Cite as:**Completing the Square - Multiple Variables.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/completing-the-square-multiple-variables/