acalculator

How to complete the square?

Type a, b and c of ax² + bx + c. The complete the square calculator writes it as a(x − h)² + k, then solves ax² + bx + c = 0 by completing the square, with every step and the roots in exact, simplified form.

Your numbers

Completed square
(x − 3/2)² − 29/4

Completing the square gives (x − 3/2)² − 29/4. Solutions: x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404.

Solutions of ax² + bx + c = 0
x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404
h
1.5
k
−7.25
Square to add
9/4
Steps
Move the constant: x² − 3x = 5; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = 29/4; Write the left side as a square: (x − 3/2)² = 29/4; Take the square root: x − 3/2 = ± √29/2; x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404

Completed square: (x − 3/2)² − 29/4. Completing the square gives (x − 3/2)² − 29/4. Solutions: x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404.

How is the square completed?

How to calculate

Completes the square of ax² + bx + c to a(x − h)² + k and solves ax² + bx + c = 0 by completing the square, with each step and exact, simplified roots.

Example with the default inputs (a 1, b −3, c −5): Completing the square gives (x − 3/2)² − 29/4. Solutions: x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404.

Method: Divide by a, move c/a across, add (b/(2a))² to both sides, write (x − h)² = q with h = −b/(2a) and q = (b² − 4ac)/(4a²), then x = h ± √q; a(x − h)² + k with k = c − b²/(4a).

  • a may not be 0. Coefficients are read as the exact decimals typed, so h, k and q are exact fractions.
  • √q is simplified exactly when q’s top times its bottom is at most 10¹⁵.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. a 1, b -3, c -5 gives Completed square (x − 3/2)² − 29/4, Solutions of ax² + bx + c = 0 x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404, Square to add 9/4, Steps Move the constant: x² − 3x = 5; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = 29/4; Write the left side as a square: (x − 3/2)² = 29/4; Take the square root: x − 3/2 = ± √29/2; x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404.Source: OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, Example 8 (x² − 3x − 5 = 0 gives x = 3/2 ± √29/2), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations
  2. a 1, b 4, c 1 gives Completed square (x + 2)² − 3, Solutions of ax² + bx + c = 0 x = −2 ± √3 ≈ −3.732050808 and −0.2679491924.Source: OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, completing the square (x² + 4x + 1 = 0 gives (x + 2)² = 3 and x = −2 ± √3), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations
  3. a 1, b -6, c -13 gives Completed square (x − 3)² − 22, Solutions of ax² + bx + c = 0 x = 3 ± √22 ≈ −1.69041576 and 7.69041576.Source: OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, Try It #7 (x² − 6x = 13), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations
  4. a 2, b -6, c 7 gives Completed square 2(x − 3/2)² + 5/2, h 1.5, k 2.5, Solutions of ax² + bx + c = 0 No real solution; complex: x = 3/2 ± (√5/2)i, Steps Divide by a = 2: x² − 3x + 7/2 = 0; Move the constant: x² − 3x = −7/2; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = −5/4; Write the left side as a square: (x − 3/2)² = −5/4; Take the square root: x − 3/2 = ± (√5/2)i; x = 3/2 ± (√5/2)i.Source: OpenStax, Algebra and Trigonometry 2e, §5.1 Quadratic Functions, Example 3 (f(x) = 2x² − 6x + 7 = 2(x − 3/2)² + 5/2), https://openstax.org/books/algebra-and-trigonometry-2e/pages/5-1-quadratic-functions
  5. a -0.5, b 2, c 6 gives Completed square −(1/2)(x − 2)² + 8, Solutions of ax² + bx + c = 0 x = −2 and x = 6, k 8.

How it works

For ax² + bx + c with a ≠ 0, all in exact fractions:

  1. Divide by a (skipped when a = 1): x² + (b/a)x + c/a = 0.
  2. Move the constant: x² + (b/a)x = −c/a.
  3. Add the square (b/(2a))² to both sides.
  4. Write the left side as a square: (x − h)² = q, with h = −b ÷ (2a) and q = −c/a + (b/(2a))² = (b² − 4ac) ÷ (4a²).
  5. Take the square root: x − h = ±√q, so x = h ± √q.

The completed square is a(x − h)² + k with k = c − b² ÷ (4a) (which equals −a × q).

Solutions. If q = 0 there is one repeated solution, x = h. If q > 0 there are two real solutions. When √q is a fraction they are written as two fractions, smaller first (x = −2 and x = 6). Otherwise they are written as h ± √q in simplified radical form, then as decimals rounded to 10 significant figures, smaller first. If q < 0 there is no real solution, and the complex solutions x = h ± (√|q|)i are given.

Simplifying √q. Write q = P/Q in lowest terms. Then √q = √(P × Q) ÷ Q. Take every square factor out of P × Q: P × Q = s² × t with t square-free, so √q = s√t ÷ Q, and s/Q is reduced to lowest terms (√116 ÷ 4 = 2√29 ÷ 4 = √29/2). When t = 1 the root is the fraction s/Q. When P × Q is above 10¹⁵, the root is not simplified and the solutions show as decimals only (x ≈ …).

Rules. a may not be 0: with no x² term there is no square to complete, and the page says so. Each coefficient is from −1,000,000 to 1,000,000. When h, k or q is too large to show as a number (beyond about 1.8 × 10³⁰⁸, from an a very close to 0), there is no answer either.

Output format. Fractions in lowest terms with a true minus sign. The completed square leaves out a = 1 (writes − for a = −1), puts a fraction a in brackets ((1/2)), writes (x − h)² as (x + |h|)² when h < 0 and as x² when h = 0, and leaves out k when it is 0. In the steps, a coefficient of 1 is not written, a fraction coefficient is in brackets, and zero terms are left out. In a complex root, i follows a bracket unless √|q| is a whole number (3 ± 2i). h and k also show as decimals with up to 10 significant figures.

Worked examples by hand

x² − 3x − 5 = 0 (OpenStax Example 8). x² − 3x = 5. Half of −3 is −3/2; (−3/2)² = 9/4. x² − 3x + 9/4 = 29/4, so (x − 3/2)² = 29/4. √(29/4) = √29/2, so x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404. Completed square: (x − 3/2)² − 29/4.

x² + 4x + 1 = 0 (OpenStax). x² + 4x = −1; add 4: (x + 2)² = 3, so x = −2 ± √3 ≈ −3.732050808 and −0.2679491924. Completed square (x + 2)² − 3.

x² − 6x = 13 (OpenStax Try It #7). c = −13. Add 9: (x − 3)² = 22, so x = 3 ± √22 ≈ −1.69041576 and 7.69041576.

2x² − 6x + 7. Divide by 2: x² − 3x + 7/2 = 0; x² − 3x = −7/2; add 9/4: (x − 3/2)² = −5/4. q < 0, so no real solution; √(5/4) = √5/2, so x = 3/2 ± (√5/2)i. k = 7 − 36/8 = 5/2: 2(x − 3/2)² + 5/2 (OpenStax §5.1 Example 3).

−0.5x² + 2x + 6. Divide by −1/2: x² − 4x − 12 = 0; x² − 4x = 12; add 4: (x − 2)² = 16; √16 = 4, so x = −2 and x = 6. k = 6 − 4/(−2) = 8: −(1/2)(x − 2)² + 8.

Other questions people ask

How do I complete the square?

For x² + bx + c = 0: move c to the right side, add (b/2)² to both sides, and write the left side as (x + b/2)². For x² − 3x − 5 = 0: x² − 3x = 5, add 9/4, (x − 3/2)² = 29/4.

What if the x² coefficient is not 1?

Divide every term by a first. 2x² − 6x + 7 = 0 becomes x² − 3x + 7/2 = 0, then complete the square as usual. For the form a(x − h)² + k, multiply back by a: 2(x − 3/2)² + 5/2.

How do I get the solutions after completing the square?

Take the square root of both sides, with ±. From (x − 3/2)² = 29/4, x − 3/2 = ±√29/2, so x = 3/2 ± √29/2.

What if the number on the right is negative?

A real square cannot be negative, so the equation has no real solution. The calculator gives the complex solutions with i = √−1: (x − 3/2)² = −5/4 gives x = 3/2 ± (√5/2)i.

How is completing the square related to the vertex?

a(x − h)² + k is the vertex form: the vertex of y = ax² + bx + c is (h, k), with h = −b ÷ (2a) and k = c − b² ÷ (4a).

How is it related to the quadratic formula?

Completing the square on ax² + bx + c = 0 in general gives (x + b/(2a))² = (b² − 4ac)/(4a²), which leads straight to the quadratic formula x = (−b ± √(b² − 4ac)) ÷ (2a).