Sub topic 5
Stretching and Compressing Vertically
This chapter covers the transformation g(x) = a·f(x). It assumes you can evaluate f(x), plot points on the coordinate plane, and sketch the parent functions x, x², |x|, √x, and x³. It also assumes you know how to find the domain and range of a function, and that you have seen vertical shifts f(x) + k.
What multiplying the output does
A vertical shift adds a number to the output. A vertical stretch or compression multiplies the output by a number. Write the new function as
g(x) = a · f(x)
where a is a nonzero constant. For every input x, the function f produces a value, and g makes that value a times as large. The input is never touched, so each point keeps its x-coordinate. Only the y-coordinate changes:
(x, y) → (x, a·y)
Every point on the graph moves straight up or straight down, away from or toward the x-axis. That is why this is called a vertical change.
Consider f(x) = x² and g(x) = 3x². At x = 2, f gives 4 and g gives 12. At x = −1, f gives 1 and g gives 3. Each y-value is tripled, so the parabola becomes narrower and steeper.
Stretch versus compression
The size of |a| decides what happens.
| Value of a | Effect on the graph | Example with f(x) = x² | Column | Column | Column | Column |
|---|---|---|---|---|---|---|
| \ | a\ | > 1 | Vertical stretch by a factor of \ | a\ | 3x² is steeper and narrower | |
| 0 < \ | a\ | < 1 | Vertical compression by a factor of \ | a\ | 0.5x² is flatter and wider | |
| a = 1 | No change | x² | ||||
| a < 0 | Reflection across the x-axis, combined with a stretch or compression by \ | a\ | −2x² opens downward and is narrower |
The words "narrower" and "wider" describe how a parabola looks, but they can mislead. A vertical stretch pulls points away from the x-axis. It does not squeeze the graph horizontally, even though the picture seems to show that. For a parabola the two descriptions agree visually. For other functions they do not, and you should think in terms of y-values.
A useful way to hold the idea is to picture the x-axis as a fixed line and the graph as a rubber sheet pinned along it. A stretch pulls the sheet away from the axis in both directions. A compression pushes it toward the axis.
Computing it in code
The function below builds g(x) = a·f(x) from any f. It is a simplified version of the general transformation helper, with only the vertical factor.
def vertical_scale(f, a):
"""Return g(x) = a * f(x)."""
return lambda x: a * f(x)
f = lambda x: x ** 2
stretched = vertical_scale(f, 3)
compressed = vertical_scale(f, 0.5)
for x in [-2, -1, 0, 1, 2]:
print(x, f(x), stretched(x), compressed(x))The output is:
-2 4 12 2.0
-1 1 3 0.5
0 0 0 0.0
1 1 3 0.5
2 4 12 2.0Notice the row for x = 0. Every version gives 0. This point matters in the next section.
Invariant points
A point stays in place under a vertical stretch or compression when a·y = y. For a ≠ 1, that happens only when y = 0. So every point on the x-axis is fixed. These points are the x-intercepts of the graph, also called zeros.
This gives a quick check. Whatever the value of a, the graph of a·f(x) crosses the x-axis at the same places as the graph of f(x). If f(x) = x² − 4 has zeros at x = −2 and x = 2, then 5(x² − 4) has the same zeros.
The y-intercept does move. If f(0) = c, then g(0) = a·c. For f(x) = x² − 4, the y-intercept is −4. For 5(x² − 4), it is −20.
f = lambda x: x ** 2 - 4
g = lambda x: 5 * f(x)
print(f(-2), g(-2)) # 0 0
print(f(2), g(2)) # 0 0
print(f(0), g(0)) # -4 -20Tracking key points
To graph a·f(x) from the graph of f(x), pick key points of f, such as intercepts, turning points, and endpoints. Multiply each y-coordinate by a. Keep each x-coordinate. Then connect the new points in the same pattern as the original.
Take f(x) = |x| with key points (−2, 2), (0, 0), (2, 2). For g(x) = 1.5|x|:
- (−2, 2) becomes (−2, 3).
- (0, 0) stays at (0, 0).
- (2, 2) becomes (2, 3).
The vertex stays at the origin. The two arms rise more steeply, with slope 1.5 and −1.5 instead of 1 and −1.
The same approach works for a function with an interesting shape, such as f(x) = x³ − x. Its zeros are at −1, 0, and 1. Its local maximum is near x ≈ −0.577 and its local minimum is near x ≈ 0.577. Multiplying by 2 doubles the heights of the maximum and minimum but leaves the three zeros alone.
Effect on slope
For linear and curved graphs, a vertical stretch multiplies the steepness. If f has slope m at some point, then a·f has slope a·m at the same x. A line y = x with slope 1 becomes y = 4x with slope 4, which is a steeper line through the same origin.
This is also why a compression makes a graph flatter. The line y = 0.25x has slope 0.25 and is much closer to the x-axis.
Since slopes scale by a, the graph of a·f(x) has the same "shape family" as f(x), but features like peaks and valleys become taller or shallower. Where f has a horizontal tangent, so does a·f. Turning points occur at the same x-values.
Domain and range
Since the inputs are untouched, the domain of a·f(x) is the same as the domain of f(x), for any nonzero a. Multiplying the outputs does change the range.
Suppose f has range [m, M]. Then:
- If a > 0, the range of a·f is [a·m, a·M].
- If a < 0, the order reverses and the range is [a·M, a·m].
For f(x) = x² the range is [0, ∞). For 3x² the range is [0, ∞) again, since 3 × 0 = 0 and the upper end is unbounded. For −3x² the range is (−∞, 0].
A bounded example shows the effect better. Take f(x) = √(4 − x²), the upper half of a circle of radius 2. Its domain is [−2, 2] and its range is [0, 2]. For g(x) = 3√(4 − x²), the domain stays [−2, 2] and the range becomes [0, 6]. The graph is now the upper half of an ellipse, three times as tall as it is... in proportion to the original height, while its width is unchanged.
import math
f = lambda x: math.sqrt(4 - x ** 2)
g = lambda x: 3 * f(x)
xs = [-2, -1, 0, 1, 2]
print([round(f(x), 3) for x in xs]) # [0.0, 1.732, 2.0, 1.732, 0.0]
print([round(g(x), 3) for x in xs]) # [0.0, 5.196, 6.0, 5.196, 0.0]Common errors
- Thinking a vertical stretch changes the zeros. It does not. Zeros are where f(x) = 0, and a·0 = 0.
- Confusing a·f(x) with f(a·x). The first changes outputs and acts the way the number looks: a larger a means a taller graph. The second changes inputs and acts in the opposite direction. That case belongs to a later chapter.
- Mixing up the order of a shift and a stretch. In a·f(x) + k, the multiplication happens first, then the shift. So the vertical shift is k, not a·k. In a·(f(x) + k), the shift happens first, so the graph moves up by a·k in total. These are different functions.
- Applying a to the x-coordinate. For a·f(x), the mapping is (x, y) → (x, a·y). The x-coordinate does not change.
- Reading a compression as "a smaller graph". A compression by a factor of 0.5 halves the heights. It does not halve the domain.
f = lambda x: x ** 2
a, k = 2, 3
g1 = lambda x: a * f(x) + k # stretch first, then shift by k
g2 = lambda x: a * (f(x) + k) # shift first, then stretch
print(g1(0), g2(0)) # 3 6
print(g1(1), g2(1)) # 5 8At x = 0, g1 sits at height 3 while g2 sits at height 6. The vertex of g2 moved up by a·k = 6.
Reading a from a graph
To find a from a graph, compare the height of one known point with the parent's height at the same x. Choose an x where the parent value is easy, and where it is not zero.
Suppose a graph is a transformed x² with its vertex at the origin and passes through (2, 12). The parent gives f(2) = 4. Then a = 12 ÷ 4 = 3, so the equation is g(x) = 3x².
If the graph passes through (1, −2), the parent gives f(1) = 1, so a = −2. This is a stretch by 2 combined with a reflection across the x-axis.
Do not use a point on the x-axis for this purpose. Both heights are 0, so the ratio is 0 ÷ 0 and tells you nothing.
Summary of the rules
| Feature | Under g(x) = a·f(x) |
|---|---|
| Point mapping | (x, y) → (x, a·y) |
| x-intercepts | Unchanged |
| y-intercept | Multiplied by a |
| Domain | Unchanged |
| Range | Endpoints multiplied by a, reversed if a < 0 |
| Slopes | Multiplied by a |
| Turning point x-values | Unchanged |
Exercise
Let f(x) = x² − 1. Describe g(x) = 0.5·f(x) as a transformation. Give the x-intercepts, the y-intercept, and the range of g.
Show answer
g is a vertical compression of f by a factor of 0.5. The x-intercepts stay at x = −1 and x = 1, because 0.5·0 = 0. The y-intercept is f(0) = −1 multiplied by 0.5, so it is −0.5. The range of f is [−1, ∞), so the range of g is [−0.5, ∞).
Exercise
A graph has the shape of y = |x| with its vertex at the origin. It passes through the point (4, −10). Write its equation.
Show answer
The parent value at x = 4 is |4| = 4. Then a = −10 ÷ 4 = −2.5. The equation is g(x) = −2.5|x|. It is a vertical stretch by 2.5 combined with a reflection across the x-axis.
Exercise
Write a short Python function that, given a list of points (x, y) and a number a, returns the points of the graph of a·f(x). Then use it on [(-1, 1), (0, 0), (1, 1)] with a = -4.
Show answer
def verticalmap(points, a): return [(x, a * y) for x, y in points] print(verticalmap([(-1, 1), (0, 0), (1, 1)], -4)) # [(-1, -4), (0, 0), (1, -4)] The x-values are unchanged and each y-value is multiplied by −4. The point (0, 0) stays fixed because it lies on the x-axis.