Function Repository Resource:

CompleteTheSquare

Source Notebook

Complete the square of a quadratic polynomial having any number of variables but with no mixed terms

Contributed by: Dennis M Schneider

ResourceFunction["CompleteTheSquare"][quad,vars]

completes the square of the quadratic polynomial quad in the variables vars that has no mixed terms.

Examples

Basic Examples (5) 

Complete the square of a quadratic polynomial in x:

In[1]:=
ResourceFunction["CompleteTheSquare"][x^2 + 2 x - 14, x]
Out[1]=

Complete the square in x of a quadratic polynomial in x and y:

In[2]:=
ResourceFunction["CompleteTheSquare"][x^2 + 2 x + 2 y^2 + 7 y == 14,
  x]
Out[2]=

Complete the square in both x and y:

In[3]:=
ResourceFunction["CompleteTheSquare"][
 x^2 + 2 x + 2 y^2 + 7 y == 14, {x, y}]
Out[3]=

Symbolic coefficients are allowed:

In[4]:=
ResourceFunction["CompleteTheSquare"][a x^2 + b x + \[Pi], x]
Out[4]=

Complete the square symbolically for a trivariate quadratic polynomial:

In[5]:=
ResourceFunction[
 "CompleteTheSquare"][(a + c)^3 x^2 + b x + 2 \[Pi] y^2 + 7 y - 14 + z^2 + (a + z)^2 == \[Pi] + Sin[2], {x, y, z}]
Out[5]=

Possible Issues (3) 

If the expression is not a polynomial, an error message is returned:

In[6]:=
ResourceFunction["CompleteTheSquare"][
 Exp[x^2] + c x + y^2 + y + 1, {x, y}]

If the expression is not a polynomial of degree 2, an error message is returned:

In[7]:=
ResourceFunction["CompleteTheSquare"][c x + y^3 + y + 1, {x, y}]

If the polynomial contains mixed terms, an error message is returned:

In[8]:=
ResourceFunction["CompleteTheSquare"][c x y + y^2 + y + 1, {x, y}]

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 09 August 2019

Related Resources

License Information