Pre-Calculus for Programmers

Algebra foundations: the toolkit calculus never reteaches

14 / 397
Contents

Contents

Pre-Calculus for Programmers

0 of 397 complete

10 min read

Completing the square

Rewriting a quadratic as a perfect square plus a leftover, which is the form that shows where its lowest point is.

x2+6xx^{2}+6x is not a perfect square, but it is close to one. (x+3)2(x+3)^{2} expands to x2+6x+9x^{2}+6x+9, which is the same thing with an unwanted 9 attached. So x2+6xx^{2}+6x ought to be (x+3)2(x+3)^{2} with the 9 taken off again. Test that against a spread of values.

Is x^2 + 6x really (x+3)^2 - 9?Python

Change both 6s to 10s and run it again: the columns disagree, because the 3 and the 9 no longer match a middle term of 10x10x. Fix the 3 and the 9 until every row agrees.

The two agree everywhere. The 3 inside the bracket is half of 6, and the 9 subtracted outside is that 3 squared. Those two facts are the entire method, and they come straight from the expansion (x+p)2=x2+2px+p2(x+p)^{2} = x^{2}+2px+p^{2}: the middle term is 2p2p, so pp has to be half of it.

The method

Completing the square means rewriting x2+bx+cx^{2}+bx+c as a perfect square bracket plus a number. Halve bb, put that inside the bracket, square it, and subtract it back outside so nothing has changed.

x2+bx+c=(x+b2)2−b24+cx^{2}+bx+c = \left(x+\frac{b}{2}\right)^{2} - \frac{b^{2}}{4} + c
Halve $b$ for the inside. Square that half and take it away outside.
The same curve, written two ways
x2+6 x+0=(x+62)2+(0−624)x^{2} + 6\,x + 0 = \left(x + \tfrac{6}{2}\right)^{2} + \left(0 - \tfrac{6^{2}}{4}\right)
-12-441220-8-4.5-12.56
completed square form
Where the lowest point sits, xx
-3
The value there
-9

The dashed curve sits exactly on the solid one for every setting, because the two expressions are the same. Drag b and watch the lowest point slide to −b/2-b/2; drag c and watch the whole curve rise and fall without moving sideways.

The completed form makes something visible that the original hides. A square is never negative, so (x+b2)2\left(x+\frac{b}{2}\right)^{2} is smallest when it is zero, which happens at x=−b2x = -\frac{b}{2}, and there the whole expression equals the leftover number. That is where the curve bottoms out and what its lowest value is.

A worked example, every step

Write x2+6x+5x^{2}+6x+5 in completed square form.

  1. Look only at x2+6xx^{2}+6x to begin with. The middle coefficient is 6.
  2. Half of 6 is 3, so the bracket is (x+3)(x+3).
  3. (x+3)2(x+3)^{2} expands to x2+6x+9x^{2}+6x+9, which is 9 more than what was wanted.
  4. Subtract that 9 straight away: x2+6x=(x+3)2−9x^{2}+6x = (x+3)^{2}-9.
  5. Now bring back the +5+5 that was set aside: x2+6x+5=(x+3)2−9+5x^{2}+6x+5 = (x+3)^{2}-9+5.
  6. Combine the numbers: −9+5=−4-9+5 = -4.
  7. So x2+6x+5=(x+3)2−4x^{2}+6x+5 = (x+3)^{2}-4, and the lowest value is −4-4, reached at x=−3x = -3.
  8. Check at x=0x = 0: the original is 5, and (0+3)2−4=9−4=5(0+3)^{2}-4 = 9-4 = 5.

When the leading coefficient is not 1

The method needs the x2x^{2} to stand alone, so take the leading coefficient out of the first two terms first, and leave the constant outside the bracket where it is.

Take 2x2−12x+72x^{2}-12x+7.

  1. Factor 2 out of the first two terms only: 2(x2−6x)+72\left(x^{2}-6x\right)+7. The 7 is untouched.
  2. Complete the square inside the bracket. Half of −6-6 is −3-3, and (−3)2=9(-3)^{2} = 9, so x2−6x=(x−3)2−9x^{2}-6x = (x-3)^{2}-9.
  3. Substitute that back in: 2[(x−3)2−9]+72\left[(x-3)^{2}-9\right]+7.
  4. Multiply the 2 through the square brackets. This is the step people miss: the −9-9 gets doubled as well, giving 2(x−3)2−18+72(x-3)^{2}-18+7.
  5. Combine the numbers: −18+7=−11-18+7 = -11.
  6. So 2x2−12x+7=2(x−3)2−112x^{2}-12x+7 = 2(x-3)^{2}-11.
  7. Check at x=0x = 0: the original is 7, and 2⋅9−11=18−11=72 \cdot 9 - 11 = 18-11 = 7.

When $b$ is odd

Nothing about the method changes when bb is odd. The only difference is that halving an odd number gives a fraction, and a fraction is not a reason to stop. Exam questions use odd values of bb far more often than tidy even ones, so this case is worth doing slowly.

Write x2+5x+3x^{2}+5x+3 in completed square form.

  1. Look only at x2+5xx^{2}+5x to begin with. The middle coefficient is 5.
  2. Half of 5 is 52\frac{5}{2}, so the bracket is (x+52)\left(x+\frac{5}{2}\right). Leave it as a fraction: 2.5 will be harder to work with in a moment, not easier.
  3. Square that half: (52)2=5222=254\left(\frac{5}{2}\right)^{2} = \frac{5^{2}}{2^{2}} = \frac{25}{4}, because a power spreads across a quotient.
  4. So (x+52)2\left(x+\frac{5}{2}\right)^{2} expands to x2+5x+254x^{2}+5x+\frac{25}{4}, which is 254\frac{25}{4} more than was wanted, and that has to come off: x2+5x=(x+52)2−254x^{2}+5x = \left(x+\frac{5}{2}\right)^{2}-\frac{25}{4}.
  5. Now bring back the +3+3: x2+5x+3=(x+52)2−254+3x^{2}+5x+3 = \left(x+\frac{5}{2}\right)^{2}-\frac{25}{4}+3.
  6. Combine the two numbers over a common denominator of 4: 3=1243 = \frac{12}{4}, so −254+124=−134-\frac{25}{4}+\frac{12}{4} = -\frac{13}{4}.
  7. So x2+5x+3=(x+52)2−134x^{2}+5x+3 = \left(x+\frac{5}{2}\right)^{2}-\frac{13}{4}, and the lowest value is −134-\frac{13}{4}, reached at x=−52x = -\frac{5}{2}.
  8. Check at x=0x = 0: the original is 3, and (52)2−134=254−134=124=3\left(\frac{5}{2}\right)^{2}-\frac{13}{4} = \frac{25}{4}-\frac{13}{4} = \frac{12}{4} = 3.

Inside an equation

In an expression, whatever is added must be taken away again in the same line, because an expression has to keep its value. In an equation there is a second option: add the same quantity to both sides, which keeps the two sides equal without any subtracting.

  1. Start from x2+6x=7x^{2}+6x = 7.
  2. Half of 6 is 3, and 32=93^{2} = 9, so add 9 to both sides: x2+6x+9=16x^{2}+6x+9 = 16.
  3. The left side is now a perfect square: (x+3)2=16(x+3)^{2} = 16.
  4. The equation now says that some quantity, squared, is 16. Check the two candidates by substitution: x=1x = 1 gives (4)2=16(4)^{2} = 16, and x=−7x = -7 gives (−4)2=16(-4)^{2} = 16. Both work.
Check yourself

Complete the square: x2−8x+3x^{2}-8x+3 equals which of these?

Write 3x2+12x+53x^{2}+12x+5 in the form a(x+p)2+qa(x+p)^{2}+q.

Take 3 out of the first two terms: 3(x2+4x)+53(x^{2}+4x)+5. Half of 4 is 2, and 22=42^{2} = 4, so x2+4x=(x+2)2−4x^{2}+4x = (x+2)^{2}-4. That gives 3[(x+2)2−4]+53\left[(x+2)^{2}-4\right]+5. Multiplying the 3 through turns −4-4 into −12-12, so it is 3(x+2)2−12+5=3(x+2)2−73(x+2)^{2}-12+5 = 3(x+2)^{2}-7. Check at x=0x = 0: the original is 5, and 3⋅4−7=53 \cdot 4 - 7 = 5.

All lessons in Pre-Calculus for Programmers