Basic Examples

Complete the square of a quadratic polynomial in
x
:
[◼]
CompleteTheSquare
[
2
x
+2x-14,x]
In[]:=
-15+
2
(1+x)
Out[]=
Complete the square in
x
of a quadratic polynomial in
x
and
y
:
[◼]
CompleteTheSquare
[
2
x
+2x+2
2
y
+7y==14,x]
In[]:=
-15+
2
(1+x)
+7y+2
2
y
Out[]=
Complete the square in both
x
and
y
:
[◼]
CompleteTheSquare
[
2
x
+2x+2
2
y
+7y==14,{x,y}]
In[]:=
-
169
8
+
2
(1+x)
+2
2
7
4
+y
Out[]=
Symbolic coefficients are allowed:
[◼]
CompleteTheSquare
[a
2
x
+bx+π,x]
In[]:=
-
2
b
4a
+π+a
2
b
2a
+x
Out[]=
Complete the square symbolically for a trivariate quadratic polynomial:
[◼]
CompleteTheSquare
[
3
(a+c)
2
x
+bx+2π
2
y
+7y-14+
2
z
+
2
(a+z)
π+Sin[2],{x,y,z}]
In[]:=
3
(a+c)
2
b
2
3
(a+c)
+x
+2π
2
7
4π
+y
+2
2
a
2
+z
+
1
8
-112+4
2
a
-
2
2
b
3
(a+c)
-
49
π
-8π-8Sin[2]
Out[]=

Possible Issues

If the expression is not a polynomial, an error message is returned:
[◼]
CompleteTheSquare
[Exp[
2
x
]+cx+
2
y
+y+1,{x,y}]
In[]:=
Poly
::notpoly
:The input expression 1+
2
x

+cx+y+
2
y
is not a quadratic polynomial in the specified variable(s) {x,y}.
If the expression is not a polynomial of degree 2, an error message is returned:
[◼]
CompleteTheSquare
[cx+
3
y
+y+1,{x,y}]
In[]:=
Poly
::notpoly
:The input expression 1+cx+y+
3
y
is not a quadratic polynomial in the specified variable(s) {x,y}.
If the polynomial contains mixed terms, an error message is returned:
[◼]
CompleteTheSquare
[cxy+
2
y
+y+1,{x,y}]
In[]:=
Poly
::mixed
:The input polynomial 1+y+cxy+
2
y
contains mixed terms.