The idea behind completing the square is to add or subtract a constant to obtain the form (x-h)^2(x−h)2 and then take a square root to be left with a linear equation. Let's do a concrete example first.
Starting from 2x^2-7x-4=02x2−7x−4=0
Step 1: Divide both sides by 22 to obtain x^2x2 as the first term
x^2-7/2x-2 = 0x2−72x−2=0
Step 2: Add 22 to both sides to isolate the xx terms.
x^2-7/2x = 2x2−72x=2
Step 3: Add a constant to both sides which will allow us to factor the left hand side as (x-h)^2(x−h)2. Noting that (x-h)^2 = x^2-2h+h^2(x−h)2=x2−2h+h2 we have -2h = -7/2−2h=−72 and thus h = 7/4h=74, meaning we add (7/4)^2 = 49/16(74)2=4916 to both sides.
x^2-7/2+49/16 = 81/16x2−72+4916=8116
Step 4: Factor the left hand side
(x-7/4)^2 = 81/16(x−74)2=8116
Step 5: Take the square root of both sides. Remember to account for both positive and negative roots.
x-7/4 = +-sqrt(81/16) = +-9/4x−74=±√8116=±94
Step 6: Solve the remaining linear equation:
x = 7/4 +- 9/4 = 1/4(7+-9)x=74±94=14(7±9)
=> x = 4⇒x=4 or x = -1/2x=−12
The real trick here is observing in step 3 that the constant we need to add is equal to the square of half of the coefficient of xx.
Let's see what happens if we apply this to a general quadratic equation.
ax^2 + bx + c = 0ax2+bx+c=0
=> x^2 + b/ax + c/a = 0⇒x2+bax+ca=0
=> x^2 + b/ax = -c/a⇒x2+bax=−ca
=> x^2 + b/ax + (b/(2a))^2 = -c/a + (b/(2a))^2 = b^2/(4a^2)-c/a⇒x2+bax+(b2a)2=−ca+(b2a)2=b24a2−ca
=> (x+b/(2a))^2 = (b^2-4ac)/(4a^2)⇒(x+b2a)2=b2−4ac4a2
=> x+b/(2a) = +-sqrt((b^2-4ac)/(4a^2)) = +-sqrt(b^2-4ac)/(2a)⇒x+b2a=±√b2−4ac4a2=±√b2−4ac2a
=> x = -b/(2a) +- sqrt(b^2-4ac)/(2a)⇒x=−b2a±√b2−4ac2a
=(-b+-sqrt(b^2-4ac))/(2a)=−b±√b2−4ac2a
And we have just derived the quadratic formula.