Sub topic 3
Completing the square
This chapter assumes you can solve linear equations, expand and factor simple expressions such as (x + 3)², and simplify square roots of numbers. It covers the algebraic technique that the next chapter uses to derive the quadratic formula. Here you only practice the technique on numeric equations.
Why this technique exists
Some quadratics are easy to solve. The equation (x + 3)² = 16 needs only a square root: x + 3 = 4 or x + 3 = −4. The equation x² + 6x − 7 = 0 looks harder, because x appears in two places. Completing the square rewrites the harder form as the easier one without changing its solutions.
The perfect-square pattern
Expanding a squared binomial gives a fixed shape:
(x + h)² = x² + 2hx + h²
The middle coefficient is twice h, and the constant is h squared. Suppose you are given x² + bx and want to make it a perfect square. Match b with 2h, so h = b/2. The constant you must add is h² = (b/2)².
| Expression | b/2 | (b/2)² to add | Result as a square |
|---|---|---|---|
| x² + 6x | 3 | 9 | (x + 3)² |
| x² − 10x | −5 | 25 | (x − 5)² |
| x² + 5x | 5/2 | 25/4 | (x + 5/2)² |
| x² − x | −1/2 | 1/4 | (x − 1/2)² |
The sign inside the parentheses is the sign of b. The number you add is always positive, because it is a square.
The pattern has a geometric reading. Picture x² + 6x as a square of side x plus two rectangles that are each 3 wide and x long. Together they form a larger square with a notch missing in one corner. The notch is 3 by 3, so adding 9 "completes" the square. The finished square has side x + 3.
The procedure when a = 1
Take x² + bx + c = 0 and follow these steps.
- Move the constant to the right side: x² + bx = −c.
- Add (b/2)² to both sides.
- Write the left side as (x + b/2)².
- Take the square root of both sides, keeping both signs.
- Solve the two linear equations.
Example with integer steps
Solve x² + 6x − 7 = 0.
- x² + 6x = 7
- Half of 6 is 3, and 3² = 9. Add 9 to both sides: x² + 6x + 9 = 16.
- (x + 3)² = 16
- x + 3 = ±4
- x = −3 + 4 = 1, or x = −3 − 4 = −7.
Check x = 1: 1 + 6 − 7 = 0. Check x = −7: 49 − 42 − 7 = 0. Both work.
Example with an odd middle coefficient
Solve x² + 5x + 1 = 0.
- x² + 5x = −1
- Half of 5 is 5/2, and (5/2)² = 25/4. Add it to both sides: x² + 5x + 25/4 = −1 + 25/4 = 21/4.
- (x + 5/2)² = 21/4
- x + 5/2 = ±√21/2
- x = −5/2 ± √21/2 = (−5 ± √21)/2
The roots are irrational, so factoring would not have found them. Completing the square works on any quadratic, which is why it can serve as the basis of a general formula.
When a is not 1
The method needs the coefficient of x² to be 1. If it is not, divide every term by a first. Dividing only some terms is a frequent mistake.
Example
Solve 3x² − 12x + 5 = 0.
- Divide by 3: x² − 4x + 5/3 = 0.
- Move the constant: x² − 4x = −5/3.
- Half of −4 is −2, and (−2)² = 4. Add 4 to both sides: x² − 4x + 4 = −5/3 + 4 = 7/3.
- (x − 2)² = 7/3
- x − 2 = ±√(7/3)
- x = 2 ± √(7/3)
You can tidy the radical. Since 7/3 = 21/9, √(7/3) = √21/3, so x = 2 ± √21/3. Numerically, x ≈ 3.528 or x ≈ 0.472.
Alternative: factor a out of the first two terms
You can keep the equation as it is and write 3(x² − 4x) + 5 = 0. Inside the parentheses you add 4. That addition is really an addition of 3 · 4 = 12 to the whole left side, so you must add 12 to the right side too, or subtract 12 elsewhere on the left. This route is where most errors with a ≠ 1 occur. Dividing first avoids the problem.
Completing the square without an equation
The same move works on an expression, as long as you add and subtract the same amount so the value is unchanged:
x² + 6x + 4 = (x² + 6x + 9) − 9 + 4 = (x + 3)² − 5
This is called vertex form. The squared term is never negative, so the smallest value of the expression is −5, reached at x = −3. That point, (−3, −5), is the lowest point of the parabola y = x² + 6x + 4. A later chapter uses this idea when it connects the discriminant to the graph.
For a general a, b and c:
a x² + b x + c = a (x + b/(2a))² + (c − b²/(4a))
You can verify this by expanding the right side. The term a · (b/(2a))² equals b²/(4a), which cancels the subtracted b²/(4a), leaving ax² + bx + c.
Checking the technique in code
The function below applies the general identity with exact fractions, so no rounding appears until the square root. It returns h and k such that ax² + bx + c = a(x + h)² + k.
import math
from fractions import Fraction
def complete_square(a, b, c):
if a == 0:
raise ValueError("a must be nonzero")
a, b, c = Fraction(a), Fraction(b), Fraction(c)
h = b / (2 * a)
k = c - b * b / (4 * a)
return h, k
def real_roots(a, b, c):
h, k = complete_square(a, b, c)
rhs = -k / Fraction(a) # (x + h)^2 = rhs
if rhs < 0:
return []
s = math.sqrt(rhs)
return sorted({float(-h - s), float(-h + s)})
print(*complete_square(1, 6, 4)) # 3 -5
print(real_roots(1, 6, -7)) # [-7.0, 1.0]
print([round(r, 4) for r in real_roots(3, -12, 5)]) # [0.4725, 3.5275]
print(real_roots(1, 2, 5)) # []The first call confirms the vertex-form example: x² + 6x + 4 = (x + 3)² − 5. The last call returns an empty list, which leads to the next section.
When the right side is negative
Solve x² + 2x + 5 = 0.
- x² + 2x = −5
- Add 1 to both sides: x² + 2x + 1 = −4.
- (x + 1)² = −4
No real number squared gives −4, so this equation has no real solutions. The sign of the right-hand side decides everything. If it is positive there are two roots, if it is zero there is exactly one (a repeated root), and if it is negative there are no real roots. This right-hand side is the seed of the discriminant, which appears in a later chapter. The complex solutions of this particular equation are also covered later.
Common errors
| Mistake | Why it is wrong | Fix |
|---|---|---|
| Adding (b/2)² to only one side | The equation is no longer equivalent | Add the same number to both sides |
| Adding b/2 or b² instead of (b/2)² | The left side is not a perfect square | Halve b first, then square |
| Writing (x + 3)² for x² − 6x + 9 | The sign inside copies the sign of b | Use (x − 3)² |
| Dropping the ± when taking the root | You lose one of the two solutions | Write ± and solve both cases |
| Dividing only the x² term by a | The other terms keep the wrong scale | Divide every term, including the constant |
| Forgetting that a multiplies the added term | Happens when a is factored out | Add a · (b/2a)² to the right side, or divide by a first |
Exercises
Exercise
Solve x² − 8x + 3 = 0 by completing the square. Give exact answers.
Show answer
Move the constant: x² − 8x = −3. Half of −8 is −4, and (−4)² = 16, so add 16: (x − 4)² = 13. Then x − 4 = ±√13, so x = 4 ± √13.
Exercise
Solve 2x² + 12x + 10 = 0 by completing the square, and check both roots.
Show answer
Divide by 2: x² + 6x + 5 = 0, so x² + 6x = −5. Add 9: (x + 3)² = 4. Then x + 3 = ±2, so x = −1 or x = −5. Check x = −1: 2 − 12 + 10 = 0. Check x = −5: 50 − 60 + 10 = 0.
Exercise
Write x² − 10x + 30 in the form (x − h)² + k and state the smallest value the expression can take.
Show answer
Add and subtract 25: x² − 10x + 25 − 25 + 30 = (x − 5)² + 5. The square is at least 0, so the smallest value is 5, reached at x = 5.