Sub topic 3
Completing the square when a = 1
This chapter assumes you can expand a binomial such as (x + h)^2, take square roots, solve linear equations, and write a quadratic in standard form, ax^2 + bx + c = 0.
Completing the square when a = 1
When a = 1, the equation is x^2 + bx + c = 0. Completing the square adds a number to the left side so that it becomes a perfect square, (x + h)^2. That number is (b/2)^2, because (x + b/2)^2 = x^2 + bx + (b/2)^2.
- Move c to the right side: x^2 + bx = -c.
- Add (b/2)^2 to both sides.
- Rewrite the left side as (x + b/2)^2.
- Take the square root of both sides and solve for x.
For x^2 + 6x + 5 = 0, move the 5 to get x^2 + 6x = -5. Add 9 to both sides to get (x + 3)^2 = 4. Then x + 3 = ±2, so x = -1 or x = -5.
import math
def solve_monic(b, c):
"""Solve x^2 + b*x + c = 0 by completing the square."""
rhs = (b / 2) ** 2 - c # the value of (x + b/2)^2
if rhs < 0:
return () # no real solutions
root = math.sqrt(rhs)
return tuple(sorted({-b / 2 - root, -b / 2 + root}))
print(solve_monic(6, 5)) # (-5.0, -1.0)
print(solve_monic(2, 1)) # (-1.0,)
print(solve_monic(0, 4)) # ()Completing the square when a is not 1
Divide every term by a first so that the x^2 coefficient becomes 1. For 2x^2 + 8x + 3 = 0, divide by 2 to get x^2 + 4x = -3/2. Add 4 to both sides: (x + 2)^2 = 5/2. Therefore x = -2 ± √(5/2).
Two roots, one repeated root, or no real roots
The number k on the right side of (x + h)^2 = k decides the type of solution.
| Value of k | Solutions | Example |
|---|---|---|
| k > 0 | Two distinct real roots | (x + 3)^2 = 4 gives x = -1 or -5 |
| k = 0 | One repeated root | (x + 1)^2 = 0 gives x = -1 |
| k < 0 | No real roots | (x + 1)^2 = -4 |
Checking your solutions
Substitute each value back into the original equation. For x = -1 in x^2 + 6x + 5, you get 1 - 6 + 5 = 0. For x = -5, you get 25 - 30 + 5 = 0. Both check.
Choosing the right method
Factoring is quickest when you can spot integer factors. Completing the square works for every quadratic, including those with non-integer roots. Try factoring first, and switch to completing the square when factors are hard to find.
From completing the square to the quadratic formula
Apply the same steps to ax^2 + bx + c = 0 with any nonzero a. Divide by a, complete the square, and you get (x + b/2a)^2 = (b^2 - 4ac)/(4a^2). Taking square roots gives the quadratic formula: x = (-b ± √(b^2 - 4ac)) / (2a). The expression b^2 - 4ac is the discriminant. It is positive for two roots, zero for one repeated root, and negative for no real roots.
Exercise
Solve x^2 - 4x - 1 = 0 by completing the square.
Show answer
Move the constant: x^2 - 4x = 1. Add 4 to both sides: (x - 2)^2 = 5. Then x = 2 ± √5.