TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › Graphs of the Trig Functions

Graphs of the Trig Functions

Plot sin⁡x\sin x against xx and you get the most famous curve in science: the sine wave. This lesson reads the shapes of the six trig graphs and shows how four numbers, amplitude, period, phase shift and vertical shift, stretch and slide a wave into any position you need.

Sine and cosine

Walk around the unit circle and record the height y=sin⁡xy = \sin x of the point as the angle xx grows. The height rises from 0 to 1 at π2\frac{\pi}{2}, falls back to 0 at π\pi, reaches −1 at 3π2\frac{3\pi}{2} and returns to 0 at 2π2\pi. Then it repeats forever.

Property y=sin⁡xy = \sin x y=cos⁡xy = \cos x
Domain all real numbers all real numbers
Range [−1,1][-1, 1] [−1,1][-1, 1]
Period 2π2\pi 2π2\pi
Zeros x=kπx = k\pi x=π2+kπx = \frac{\pi}{2} + k\pi
Maximum 1 at x=π2+2kπx = \frac{\pi}{2} + 2k\pi x=2kπx = 2k\pi
Symmetry odd: sin⁡(−x)=−sin⁡x\sin(-x) = -\sin x even: cos⁡(−x)=cos⁡x\cos(-x) = \cos x

(kk is any integer.) The cosine graph is the sine graph shifted left by π2\frac{\pi}{2}, because cos⁡x=sin⁡(x+π/2)\cos x = \sin(x + \pi/2).

Tangent and the reciprocal functions

tan⁡x=sin⁡x/cos⁡x\tan x = \sin x / \cos x is undefined wherever cos⁡x=0\cos x = 0, that is at x=π2+kπx = \frac{\pi}{2} + k\pi. Near those points the denominator approaches 0 and the graph shoots off to ±∞\pm\infty: these are vertical asymptotes. Between them tan⁡x\tan x increases through every real value. Its period is π\pi, not 2π2\pi.

The reciprocals csc⁡x=1/sin⁡x\csc x = 1/\sin x and sec⁡x=1/cos⁡x\sec x = 1/\cos x have asymptotes where sin⁡\sin or cos⁡\cos is 0, and their ranges are (−∞,−1]∪[1,∞)(-\infty, -1] \cup [1, \infty). cot⁡x=cos⁡x/sin⁡x\cot x = \cos x / \sin x looks like a reflected, shifted tangent.

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

x = np.linspace(-2 * np.pi, 2 * np.pi, 2000)
tan = np.tan(x)
tan[np.abs(tan) > 6] = np.nan          # break the line at the asymptotes

plt.figure(figsize=(7, 4))
plt.plot(x, np.sin(x), label="sin x")
plt.plot(x, np.cos(x), label="cos x")
plt.plot(x, tan, label="tan x", alpha=0.7)
for k in range(-2, 2):
    plt.axvline(np.pi / 2 + k * np.pi, color="gray", ls=":", lw=0.8)
plt.ylim(-3, 3); plt.axhline(0, color="black", lw=0.6)
plt.xticks(np.arange(-2, 2.5, 0.5) * np.pi, [f"{v:g}π" for v in np.arange(-2, 2.5, 0.5)])
plt.legend(loc="upper right"); plt.grid(alpha=0.3)
plt.title("sin, cos and tan (dotted lines: asymptotes of tan)")
print("tan just below π/2:", round(float(np.tan(np.pi / 2 - 1e-3)), 2))
print("tan just above π/2:", round(float(np.tan(np.pi / 2 + 1e-3)), 2))
tan just below π/2: 1000.0
tan just above π/2: -1000.0

Transforming a wave

The general sinusoid is

y=A⋅sin⁡(B(x−C))+Dy = A \cdot \sin(B(x - C)) + D
∣A∣amplitude: half the distance from trough to peak2π/∣B∣period: length of one full cycle (frequency=∣B∣/2π)Cphase shift: the wave moves right by CDvertical shift: the midline is y=D\begin{aligned} &\lvert A \rvert && \text{amplitude: half the distance from trough to peak} \\ &2\pi / \lvert B \rvert && \text{period: length of one full cycle (frequency} = \lvert B \rvert / 2\pi\text{)} \\ &C && \text{phase shift: the wave moves right by } C \\ &D && \text{vertical shift: the midline is } y = D \end{aligned}

These are the same moves as for any function in Translations, Reflections and Rotations and Composition and Inverse Functions. Example: y=3sin⁡(2(x−π/4))+1y = 3\sin(2(x - \pi/4)) + 1 has amplitude 3, period π\pi, starts a cycle at x=π4x = \frac{\pi}{4} and oscillates between −2 and 4.

Tip: Watch out for y=sin⁡(2x−π/2)y = \sin(2x - \pi/2). Factor it as sin⁡(2(x−π/4))\sin(2(x - \pi/4)): the phase shift is π4\frac{\pi}{4}, not π2\frac{\pi}{2}.

Reading the four numbers back from data is a common task. Here we sample a wave and recover them:

python · try it yourself
import numpy as np

x = np.linspace(0, 2 * np.pi, 100_001)
y = 3 * np.sin(2 * (x - np.pi / 4)) + 1

top, bottom = y.max(), y.min()
print("amplitude A =", round(float((top - bottom) / 2), 4))
print("midline   D =", round(float((top + bottom) / 2), 4))

# period: distance between two successive upward crossings of the midline
ups = x[1:][(y[:-1] < 1) & (y[1:] >= 1)]
print("upward midline crossings:", [round(float(u / np.pi), 4) for u in ups], "(× π)")
print("period =", round(float((ups[1] - ups[0]) / np.pi), 4), "π")
amplitude A = 3.0
midline   D = 1.0
upward midline crossings: [0.25, 1.25] (× π)
period = 1.0 π

The first upward crossing at x=π4x = \frac{\pi}{4} is the phase shift, and crossings one period apart confirm the period π\pi.

In software

Sine waves are everywhere a value must move smoothly back and forth.

  • Animation. A floating pickup bobs with y=base+A⋅sin⁡(2π⋅f⋅t)y = \text{base} + A \cdot \sin(2\pi \cdot f \cdot t); a "breathing" button scales with 1+0.05⋅sin⁡(ωt)1 + 0.05 \cdot \sin(\omega t). Using sin⁡\sin rather than a linear back-and-forth gives a natural ease at the turning points, because the curve is flat at its peaks.
  • Audio. A pure tone of frequency ff sampled at rate RR is the sequence sin⁡(2π⋅f⋅n/R)\sin(2\pi \cdot f \cdot n / R). Concert A is 440 Hz; CD audio uses R=44 100R = 44\,100 samples per second.
  • Day/night cycles, tides, seasonal demand in simulations and forecasts are modelled with a sinusoid plus a midline.
  • Phase lines up several waves: a row of objects with phase k⋅0.3k \cdot 0.3 creates a travelling wave, like a crowd doing the wave.
python · try it yourself
import math

def bob(t, base=100.0, amp=8.0, freq=0.5, phase=0.0):
    """Height of a floating object at time t (seconds)."""
    return base + amp * math.sin(2 * math.pi * freq * t + phase)

print("bobbing:", [round(bob(t), 2) for t in (0, 0.5, 1.0, 1.5, 2.0)])

# first 6 samples of a 440 Hz tone at 44.1 kHz, as 16-bit integers
R, f = 44_100, 440
samples = [round(32767 * 0.5 * math.sin(2 * math.pi * f * n / R)) for n in range(6)]
print("pcm samples:", samples)
print("samples per cycle:", round(R / f, 3))
bobbing: [100.0, 108.0, 100.0, 92.0, 100.0]
pcm samples: [0, 1026, 2049, 3063, 4065, 5052]
samples per cycle: 100.227

The Waves, Sound and Signals lesson goes further, and /signals-fourier/ shows that every periodic signal is a sum of such waves.

Exercises

Exercise 1: Read the parameters

For y=−2cos⁡(πx/3)+5y = -2\cos(\pi x/3) + 5, give the amplitude, period, midline, maximum and minimum.

Answer

Amplitude 2, period 6, midline y=5y = 5, maximum 7, minimum 3.

Solution
A=−2→amplitude ∣A∣=2(the minus sign flips the wave upside down)B=π/3→period=2π/(π/3)=6D=5→midline y=5, range [5−2,5+2]=[3,7]\begin{aligned} A &= -2 \to \text{amplitude } \lvert A \rvert = 2 && \text{(the minus sign flips the wave upside down)} \\ B &= \pi/3 \to \text{period} = 2\pi / (\pi/3) = 6 \\ D &= 5 \to \text{midline } y = 5,\ \text{range } [5 - 2, 5 + 2] = [3, 7] \end{aligned}

Exercise 2: Phase shift trap

Find the period and phase shift of y=sin⁡(4x+π)y = \sin(4x + \pi).

Answer

Period π2\frac{\pi}{2}, phase shift −π4-\frac{\pi}{4} (left by π4\frac{\pi}{4}).

Solution
sin⁡(4x+π)=sin⁡(4(x+π/4))=sin⁡(4(x−(−π/4)))period=2π/4=π/2,C=−π/4\begin{aligned} &\sin(4x + \pi) = \sin(4(x + \pi/4)) = \sin(4(x - (-\pi/4))) \\ &\text{period} = 2\pi/4 = \pi/2, \quad C = -\pi/4 \end{aligned}

Exercise 3: Build a model

A Ferris wheel of diameter 40 m has its centre 22 m above the ground and turns once every 8 minutes. A rider boards at the lowest point at t=0t = 0. Write the height h(t)h(t) in metres and find it at t=2t = 2 and t=3t = 3 minutes.

Answer

h(t)=22−20cos⁡(πt/4)h(t) = 22 - 20\cos(\pi t/4); h(2)=22 mh(2) = 22\ \text{m}, h(3)≈36.14 mh(3) \approx 36.14\ \text{m}.

Solution

Amplitude 20 (the radius), midline 22, period 8 so B=2π/8=π/4B = 2\pi/8 = \pi/4. Starting at the bottom means a flipped cosine.

python · try it yourself
import math
h = lambda t: 22 - 20 * math.cos(math.pi * t / 4)
print(round(h(0), 2), round(h(2), 2), round(h(3), 2), round(h(4), 2))
2.0 22.0 36.14 42.0

Exercise 4: Asymptotes

List the vertical asymptotes of y=tan⁡(2x)y = \tan(2x) in the interval [0,π][0, \pi].

Answer

x=π4x = \frac{\pi}{4} and x=3π4x = \frac{3\pi}{4}.

Solution

tan⁡u\tan u is undefined at u=π/2+kπu = \pi/2 + k\pi. With u=2xu = 2x: x=π/4+kπ/2x = \pi/4 + k\pi/2. In [0,π][0, \pi] that gives k=0k = 0 and k=1k = 1: π4\frac{\pi}{4} and 3π4\frac{3\pi}{4}. The period of tan⁡(2x)\tan(2x) is π2\frac{\pi}{2}, so asymptotes are π2\frac{\pi}{2} apart.

Exercise 5: A pulsing button

Write pulse(t) returning a scale factor that oscillates between 0.95 and 1.05 with a period of 1.2 s, starting at 1.0 and growing. Print it at t=0,0.3,0.6,0.9t = 0, 0.3, 0.6, 0.9.

Answer

1+0.05⋅sin⁡(2πt/1.2)1 + 0.05 \cdot \sin(2\pi t/1.2): 1.0, 1.05, 1.0, 0.95.

Solution

Midline 1, amplitude 0.05, B=2π/1.2B = 2\pi/1.2. A quarter period (0.3 s) reaches the peak.

python · try it yourself
import math
pulse = lambda t: 1 + 0.05 * math.sin(2 * math.pi * t / 1.2)
print([round(pulse(t), 4) for t in (0, 0.3, 0.6, 0.9)])
[1.0, 1.05, 1.0, 0.95]

Test yourself

What is the period of y=5sin⁡(3x)y = 5\sin(3x)?

  1. 5
  2. 3
  3. 2π3\frac{2\pi}{3}
  4. 6π6\pi

Where does y=tan⁡xy = \tan x have vertical asymptotes?

  1. At x=kπx = k\pi
  2. At x=π/2+kπx = \pi/2 + k\pi
  3. At x=2kπx = 2k\pi
  4. It has none

A game object bobs with y=50+4sin⁡(2π⋅0.25⋅t)y = 50 + 4\sin(2\pi \cdot 0.25 \cdot t). How long is one full bob?

  1. 0.25 s
  2. 4 s
  3. 2π2\pi s
  4. 50 s