Int 3 for Programmers

Functions, transformations, composition and inverses

10 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

10 min read

Two changes at once, and why the order matters

Combining transformations, reading them off a formula, and the factoring trap.

Putting on socks and then shoes gives a different result from putting on shoes and then socks. Transformations are the same: doing two of them in the other order usually lands the graph somewhere else.

Here are the same two changes applied in the two possible orders. Run it and compare the columns.

Try CodePython

Change the 3 to 0 and run it again. With nothing to raise by, the two columns agree, which tells you the disagreement came from the shift and not the stretch.

At x=0x = 0 the first column gives 3 and the second gives 6. Stretching first and then raising by 3 lifts the graph by 3. Raising by 3 and then stretching lifts it by 3 and then doubles that lift as well.

So the order is not a matter of taste. It is decided by the formula, and reading it correctly is reading the brackets correctly.

The general form

Every combination of the four transformations can be written in one shape.

g(x)=a f(b(x−h))+kg(x) = a \, f\bigl(b(x - h)\bigr) + k
a stretches vertically, b squashes horizontally, h shifts right, k shifts up.

Work from the inside out, because that is the order the arithmetic actually happens in. The input meets x−hx - h first, then the multiplication by bb, then ff itself, then the multiplication by aa, then the addition of kk.

  1. Horizontal: shift by hh and squash by bb. These two act on the input.
  2. Then apply the parent function.
  3. Vertical: stretch by aa, then shift by kk. These two act on the output, stretch before shift.

The vertical pair is where marks are lost. In af(x)+ka f(x) + k the stretch is applied to f(x)f(x) and not to kk, so the shift happens after the stretch. Someone who shifts first and then stretches moves the graph akak instead of kk.

Before moving the sliders, fix what bb does. The widget below opens with b=2b = 2, which means the height the plain parabola reached one unit from its centre is now reached half a unit from the centre. Drag bb down to 0.5 and the opposite happens: what was reached at one unit from the centre is now reached at two units, so the curve widens.

The general form on a parabola
y=0.5(2(x−(2)))2+(−3)y = 0.5\bigl(2(x - (2))\bigr)^2 + (-3)
-8-4048-6-3036
Turning point xx
2
Turning point yy
-3
Height one unit right of the turning point
-1

Drag b and watch the parabola narrow and widen while the turning point stays at x=hx = h: the squashing happens around the shifted centre, not around the origin. Then drag h and watch the whole thing slide.

The trap: factor the inside first

A formula does not always arrive in the tidy form. Consider y=(2x−6)2y = (2x - 6)^2. It is tempting to read the 6 as a shift of 6 to the right, and that is wrong. Check it against a table.

Try CodePython

Change the 6 to 10 and run it again. The zero moves to the input that makes the bracket vanish, which is half of the number you wrote.

The output is zero at x=3x = 3, not at x=6x = 6. Factoring the inside shows why: 2x−6=2(x−3)2x - 6 = 2(x - 3), so y=(2(x−3))2y = \bigl(2(x-3)\bigr)^2, which is a shift of 3 right and a horizontal squash by a factor of 2.

One worked example in full. Describe the transformations that take y=x2y = x^2 to y=−3(2x+8)2+1y = -3(2x + 8)^2 + 1, in order.

  1. Factor the inside: 2x+8=2(x+4)2x + 8 = 2(x + 4), so the rule is y=−3(2(x+4))2+1y = -3\bigl(2(x+4)\bigr)^2 + 1.
  2. Horizontal shift: x+4x + 4 is x−(−4)x - (-4), so h=−4h = -4, a move of 4 to the left.
  3. Horizontal squash: b=2b = 2, so every horizontal distance from the centre is halved.
  4. Vertical stretch: a=−3a = -3, so heights are tripled and then flipped over the horizontal axis.
  5. Vertical shift: k=1k = 1, so finally the whole thing rises by 1.
  6. Check with a point: at x=−4x = -4 the output is −3(0)+1=1-3(0) + 1 = 1, so the turning point is (−4,1)(-4, 1), which agrees.
Is the graph of y=2∣x∣+6y = 2|x| + 6 the same as the graph of y=2(∣x∣+6)y = 2(|x| + 6)?

No. The first is a stretch by 2 and then a rise of 6, so its corner is at (0,6)(0, 6). The second raises by 6 first and then doubles everything, giving 2∣x∣+122|x| + 12, whose corner is at (0,12)(0, 12). The stretch multiplies whatever is inside its brackets, including any shift already applied.

Check yourself

What horizontal transformation takes y=f(x)y = f(x) to y=f(3x−12)y = f(3x - 12)?

All lessons in Int 3 for Programmers