TExcelTAD
Home › Calculus Essentials › Graph Transformations

Graph Transformations

Once you know the graph of a basic function such as x2x^2, x\sqrt{x} or sin⁡x\sin x, you can draw a whole family of related graphs by shifting, stretching and reflecting it. These four moves explain what every constant in a formula like y=3sin⁡(2(x−1))+4y = 3\sin(2(x - 1)) + 4 does to the picture.

The four moves

Start from y=f(x)y = f(x). Changes outside the function act on the output (vertically); changes inside act on the input (horizontally), and they act "backwards".

New function Effect on the graph of ff
f(x)+kf(x) + k shift up by kk (down if k<0k < 0)
f(x−h)f(x - h) shift right by hh (left if h<0h < 0)
a⋅f(x)a \cdot f(x) stretch vertically by aa (squash if 0<a<10 < a < 1)
f(b⋅x)f(b \cdot x) squash horizontally by bb (stretch if 0<b<10 < b < 1)
−f(x)-f(x) reflect in the xx-axis (upside down)
f(−x)f(-x) reflect in the yy-axis (left-right)

Why "backwards" inside? The graph of f(x−2)f(x - 2) reaches the value f(0)f(0) when x−2=0x - 2 = 0, that is at x=2x = 2. Every feature arrives 2 units later, so the graph moves right. In the same way f(2x)f(2x) reaches f(4)f(4) already at x=2x = 2, so everything happens twice as fast and the graph is squashed toward the yy-axis.

Seeing it

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

xs = np.linspace(-4, 6, 400)
def f(x):
    return x**2

plt.figure(figsize=(6, 4))
plt.plot(xs, f(xs), label="x²", linewidth=2)
plt.plot(xs, f(xs - 2), label="(x − 2)²   right 2")
plt.plot(xs, f(xs) + 3, label="x² + 3   up 3")
plt.plot(xs, 0.5 * f(xs), label="0.5·x²   flatter")
plt.plot(xs, -f(xs + 1), label="−(x + 1)²   left 1, flipped")
plt.ylim(-6, 10); plt.grid(alpha=0.3); plt.legend(fontsize=8)
plt.title("Transformations of y = x²")

for name, vx, vy in [("x²", 0, 0), ("(x − 2)²", 2, 0), ("x² + 3", 0, 3), ("−(x + 1)²", -1, 0)]:
    print(f"{name:10} vertex at ({vx}, {vy})")
x²         vertex at (0, 0)
(x − 2)²   vertex at (2, 0)
x² + 3     vertex at (0, 3)
−(x + 1)²  vertex at (-1, 0)

Combining transformations

The general form

y=a⋅f(b(x−h))+ky = a \cdot f(b(x - h)) + k

applies, in order: a horizontal squash by bb, a shift right by hh, a vertical stretch by aa (a flip if a<0a < 0), and a shift up by kk. A point (x0,y0)(x_0, y_0) on the graph of ff moves to:

(x0b+h, a⋅y0+k)\left( \frac{x_0}{b} + h,\ a \cdot y_0 + k \right)

Example. y=2(x−1)2−3y = 2(x - 1)^2 - 3 is x2x^2 stretched vertically by 2, moved right 1 and down 3. The vertex goes from (0,0)(0, 0) to (1,−3)(1, -3), and the point (1,1)(1, 1) goes to (2,−1)(2, -1).

python · try it yourself
def transform(point, a=1, b=1, h=0, k=0):
    x0, y0 = point
    return (x0 / b + h, a * y0 + k)

base = [(-1, 1), (0, 0), (1, 1), (2, 4)]       # points on y = x²
for p in base:
    q = transform(p, a=2, h=1, k=-3)
    x, y = q
    check = 2 * (x - 1)**2 - 3
    print(f"{p} -> {q}   on new curve: {abs(check - y) < 1e-12}")
(-1, 1) -> (0.0, -1)   on new curve: True
(0, 0) -> (1.0, -3)   on new curve: True
(1, 1) -> (2.0, -1)   on new curve: True
(2, 4) -> (3.0, 5)   on new curve: True

Tip: To read a formula, rewrite the inside as b(x−h)b(x - h). For sin⁡(2x−6)\sin(2x - 6) that is sin⁡(2(x−3))\sin(2(x - 3)): squash by 2, then shift right by 3, not by 6.

Transforming a sine wave

Trig functions use the same moves with special names:

y=Asin⁡(B(x−C))+Dy = A \sin(B(x - C)) + D
Constant Name Effect
∣A∣\lvert A \rvert amplitude height of the wave above its midline
2π/B2\pi/B period length of one full cycle
CC phase shift horizontal shift
DD vertical shift midline y=Dy = D

y=3sin⁡(2(x−1))+4y = 3\sin(2(x - 1)) + 4 oscillates between 1 and 7 (midline 4, amplitude 3), repeats every π\pi units and is shifted right by 1.

python · try it yourself
import numpy as np

xs = np.linspace(0, 10, 100001)
ys = 3 * np.sin(2 * (xs - 1)) + 4
print("min:", round(ys.min(), 4), " max:", round(ys.max(), 4))
print("period 2π/2 =", round(2 * np.pi / 2, 4))
print("y(1) =", 3 * np.sin(0) + 4, "(starts on the midline at the phase shift)")
min: 1.0  max: 7.0
period 2π/2 = 3.1416
y(1) = 4.0 (starts on the midline at the phase shift)

In software

  • UI animation and CSS: transform: translate(…) scale(…) is exactly shifting and stretching. An easing curve e(t)e(t) on [0,1][0, 1] is reused for any duration TT and distance dd as d⋅e(t/T)d \cdot e(t/T): a horizontal stretch by TT and a vertical stretch by dd.
  • Audio: volume is amplitude (AA), pitch is frequency (BB), and a delay is a phase shift (CC).
  • Data normalisation: z=(x−μ)/σz = (x - \mu)/\sigma shifts data by the mean and squashes it by the standard deviation before feeding it to a model.
  • Graphics: model, view and projection matrices are combined shifts, scales and reflections in 2D and 3D (TRS).

Exercises

Exercise 1: Describe the moves

Describe how to get each graph from y=xy = \sqrt{x}: (a) y=x+4y = \sqrt{x + 4}, (b) y=−x+2y = -\sqrt{x} + 2, (c) y=3xy = \sqrt{3x}.

Answer

(a) left 4; (b) flip in the xx-axis, then up 2; (c) squash horizontally by a factor of 3.

Solution
  • (a) x+4=x−(−4)x + 4 = x - (-4), so h=−4h = -4: a shift of 4 to the left. The graph now starts at (−4,0)(-4, 0).
  • (b) The minus sign outside reflects in the xx-axis, +2+ 2 outside lifts it. It starts at (0,2)(0, 2) and goes down.
  • (c) A factor inside multiplies the input, so features arrive 3 times sooner: the point (9,3)(9, 3) moves to (3,3)(3, 3).

Exercise 2: Move a point

The point (2,5)(2, 5) lies on y=f(x)y = f(x). Where does it go on y=3f(x−4)−1y = 3f(x - 4) - 1?

Answer

(6,14)(6, 14)

Solution
x: shift right 42→6y: stretch 3, down 15→3⋅5−1=14\begin{aligned} x&{:}\ \text{shift right 4} && 2 \to 6 \\ y&{:}\ \text{stretch 3, down 1} && 5 \to 3 \cdot 5 - 1 = 14 \end{aligned}

Check: at x=6x = 6 the new function gives 3f(2)−1=3⋅5−1=143f(2) - 1 = 3 \cdot 5 - 1 = 14.

Exercise 3: Write the formula

Write the equation of the parabola obtained by moving y=x2y = x^2 left 3, flipping it upside down and moving it up 5. Where is its vertex and where does it cross the yy-axis?

Answer

y=−(x+3)2+5y = -(x + 3)^2 + 5; vertex (−3,5)(-3, 5); yy-intercept −4.

Solution
left 3:(x+3)2flip:−(x+3)2up 5:−(x+3)2+5x=0:−9+5=−4\begin{aligned} \text{left 3:} &\quad (x + 3)^2 \\ \text{flip:} &\quad -(x + 3)^2 \\ \text{up 5:} &\quad -(x + 3)^2 + 5 \\ x = 0{:} &\quad -9 + 5 = -4 \end{aligned}

Exercise 4: Fit a sine wave

A day's temperature swings between 12 °C at 4 am and 26 °C at 4 pm, repeating every 24 hours. Write T(t)=Asin⁡(B(t−C))+DT(t) = A \sin(B(t - C)) + D with tt in hours and check it in Python at t=4t = 4 and t=16t = 16.

Answer

T(t)=7sin⁡(π12(t−10))+19T(t) = 7\sin\left(\frac{\pi}{12}(t - 10)\right) + 19, giving 12 at t=4t = 4 and 26 at t=16t = 16.

Solution
D=26+122=19midlineA=26−122=7amplitudeB=2π24=π12period 24 hThe sine rises through its midline a quarter period (6 h) before its maximum: C=16−6=10\begin{aligned} D &= \frac{26 + 12}{2} = 19 && \text{midline} \\ A &= \frac{26 - 12}{2} = 7 && \text{amplitude} \\ B &= \frac{2\pi}{24} = \frac{\pi}{12} && \text{period 24 h} \\ &\text{The sine rises through its midline a quarter period (6 h) before its maximum: } C = 16 - 6 = 10 \end{aligned}
python · try it yourself
import math

def T(t):
    return 7 * math.sin(math.pi / 12 * (t - 10)) + 19

print(round(T(4), 6), round(T(16), 6), round(T(10), 6))
12.0 26.0 19.0

Test yourself

How is the graph of y=f(x+5)y = f(x + 5) related to y=f(x)y = f(x)?

  1. Shifted right 5
  2. Shifted up 5
  3. Shifted left 5
  4. Stretched by 5

What is the period of y=4sin⁡(3x)−2y = 4\sin(3x) - 2?

  1. 2π/32\pi/3
  2. 3
  3. 6π6\pi
  4. 4

Which formula reflects y=exy = e^x in the yy-axis?

  1. −ex-e^x
  2. e−xe^{-x}
  3. 1/(−ex)1/(-e^x)
  4. ex−1e^x - 1