Chapter 1
25 min read
Section 7 of 353

Trigonometric Functions: Circular Motion

Mathematical Functions - The Building Blocks

Learning Objectives

By the end of this section you will be able to:

  1. Define sine, cosine, tangent and their reciprocals from both the right-triangle picture and the unit-circle picture, and explain why the unit-circle definition is the "true" one.
  2. Convert fluently between degrees and radians, and explain why radians are the natural angle unit for calculus.
  3. Recognise the four-parameter wave family y=Asin(B(xC))+Dy = A\,\sin\bigl(B(x - C)\bigr) + D and read off amplitude, period, phase and offset from a graph.
  4. Apply the Pythagorean, sum, and double-angle identities to simplify expressions and solve modeling problems.
  5. Model periodic phenomena (sound, AC current, tides, body temperature, orbital motion) with sinusoidal functions.
  6. Compute trig values in Python and explain why np.sinnp.sin expects radians, never degrees.

The Story: Where Trigonometry Came From

Trigonometry was invented twice. The first time, around 2,000 years ago, by astronomers (Hipparchus, Ptolemy) who needed to predict where a planet would appear in the night sky. The geometry of a circle was the only way to handle the rotation of the heavens. The second time, in the 17th and 18th centuries, the same functions were rediscovered as the natural way to describe any oscillation: a pendulum, a vibrating string, an AC voltage, a sound wave, a heartbeat.

Why this matters: Anything that repeats — a planet circling the sun, a guitar string vibrating, your circadian rhythm, the alternating current in a wall outlet, the bit pattern of a Wi-Fi signal — speaks the language of sine and cosine. Once you can read this language, periodic motion becomes a four-knob machine you can dial in.

The single most important picture in trigonometry is the unit circle — a circle of radius 1 centered at the origin. Every trig function is just a different way of measuring something about a point walking around that circle.

Interactive Unit Circle — drag the point

Walk around the circle and watch cos θ and sin θ appear as the horizontal and vertical shadows of the moving point.

xy(0.866, 0.500)θ
Display angle in:
θ = 0.167·π rad (= 30.0°)
cos θ = 0.86603
sin θ = 0.50000
tan θ = 0.57735
green segment = cos θ (the x-coordinate).
purple segment = sin θ (the y-coordinate).
The yellow wedge area is θ/2 — that is why radians are the natural angle unit.

The one-sentence intuition. A point moves around the unit circle. Its x-coordinate is cos θ. Its y-coordinate is sin θ. Everything else — the graphs, the identities, the calculus — flows from this one fact.


First Definition: Ratios in a Right Triangle

Drop a perpendicular from the moving point to the x-axis. You get a right triangle whose hypotenuse is the radius (length 1), whose horizontal leg has length cosθ\cos\theta, and whose vertical leg has length sinθ\sin\theta. The ancient definitions are the three ratios you can form from the three sides:

sinθ=oppositehypotenuse,cosθ=adjacenthypotenuse,tanθ=oppositeadjacent\displaystyle \sin\theta = \frac{\text{opposite}}{\text{hypotenuse}}, \quad \cos\theta = \frac{\text{adjacent}}{\text{hypotenuse}}, \quad \tan\theta = \frac{\text{opposite}}{\text{adjacent}}

The schoolroom mnemonic SOH-CAH-TOA is just these three ratios. They work fine for angles between 00 and π/2\pi/2 (a right triangle cannot have an obtuse angle as the angle of interest). But what about θ=120\theta = 120^\circ? Or θ=45\theta = -45^\circ? Or a full rotation of θ=720\theta = 720^\circ? The triangle picture breaks. We need the unit-circle picture.

The right-triangle definition is a stepping stone. From here on we will use the unit circle as the "real" definition, because it works for every real number θ — positive, negative, huge, tiny, anything.

Better Definition: The Unit Circle

Place a circle of radius 1 at the origin. Measure an angle θ\theta counter-clockwise from the positive x-axis. The point where the rotating radius meets the circle has coordinates

(cosθ,  sinθ).\bigl(\cos\theta,\; \sin\theta\bigr).

That is the definition. Three things become immediate consequences:

  1. Pythagorean identity. The point sits on a circle of radius 1, so by the distance formula cos2θ+sin2θ=1\cos^2\theta + \sin^2\theta = 1. Always.
  2. Range. Coordinates on a unit circle live in [1,1][-1, 1], so 1sinθ1-1 \le \sin\theta \le 1 and 1cosθ1-1 \le \cos\theta \le 1.
  3. Periodicity. Going around once returns you to the start, so sin(θ+2π)=sinθ\sin(\theta + 2\pi) = \sin\theta and the same for cosine.

What changed

The right triangle defines sin and cos using lengths (always positive). The unit circle defines them using coordinates (signed). That sign is exactly what lets sin and cos be negative in quadrants III and IV.

Why Radians? The Natural Angle Unit

A degree is a human invention: the Babylonians divided a full turn into 360 because 360 has many divisors (and roughly matches the number of days in a year). It is a pragmatic choice with no mathematical justification.

A radian, in contrast, is the angle subtended at the center of a circle by an arc equal in length to the radius. On the unit circle this means:

θ in radians=arc length on the unit circle.\theta \text{ in radians} = \text{arc length on the unit circle.}

A full turn traces an arc of length 2π2\pi, so 360=2π360^\circ = 2\pi radians. The conversion is

θrad=π180θdeg,θdeg=180πθrad.\theta_{\text{rad}} = \frac{\pi}{180}\, \theta_{\text{deg}}, \qquad \theta_{\text{deg}} = \frac{180}{\pi}\, \theta_{\text{rad}}.
DegreesRadiansCommon name
0no rotation
30°π/6small triangle angle
45°π/4diagonal of a square
60°π/3equilateral triangle
90°π/2quarter turn
180°πhalf turn
270°3π/2three-quarter turn
360°full turn
From this point on, angles in calculus are in radians by default. Every derivative rule you will meet — ddxsinx=cosx\tfrac{d}{dx}\sin x = \cos x requires radians. The same formula in degrees becomes ugly: ddxsinx=π180cosx\tfrac{d}{dx}\sin x^\circ = \tfrac{\pi}{180}\cos x^\circ. Radians are not optional; they are the unit the math is written in.
📐 Worked example: convert 240° to radians by hand

Start from the formula θrad=π180θdeg\theta_{\text{rad}} = \tfrac{\pi}{180}\, \theta_{\text{deg}}. Substitute 240:

θrad=π180240=240π180.\theta_{\text{rad}} = \tfrac{\pi}{180} \cdot 240 = \tfrac{240\pi}{180}.

Simplify the fraction. Divide top and bottom by 60:

240π180=4π3.\tfrac{240\pi}{180} = \tfrac{4\pi}{3}.

Numerical check: 4π343.1415934.189\tfrac{4\pi}{3} \approx \tfrac{4 \cdot 3.14159}{3} \approx 4.189 radians. Since one full turn is 2π6.2832\pi \approx 6.283, the value 4.189 should land two-thirds of the way around the circle — and 240° is indeed two-thirds of 360°. ✓


Special Angles You Must Know

There are five angles whose sine and cosine you should be able to recall in your sleep. They come from the geometry of two simple triangles: the 45-45-90 (half a unit square) and the 30-60-90 (half an equilateral triangle).

θ (rad)θ (deg)cos θsin θtan θ
0100
π/630°√3/21/21/√3
π/445°√2/2√2/21
π/360°1/2√3/2√3
π/290°01undefined

A memory trick

Write the five sin values as 02,12,22,32,42\tfrac{\sqrt{0}}{2}, \tfrac{\sqrt{1}}{2}, \tfrac{\sqrt{2}}{2}, \tfrac{\sqrt{3}}{2}, \tfrac{\sqrt{4}}{2}. Cosine is the same sequence in reverse. Once you see it, you can never unsee it.

All Six Trig Functions

From sine and cosine you can build four more functions by taking ratios and reciprocals. You only need to memorize the two; the rest are derived:

tanθ=sinθcosθ,cotθ=cosθsinθ=1tanθ,\tan\theta = \frac{\sin\theta}{\cos\theta}, \qquad \cot\theta = \frac{\cos\theta}{\sin\theta} = \frac{1}{\tan\theta},
secθ=1cosθ,cscθ=1sinθ.\sec\theta = \frac{1}{\cos\theta}, \qquad \csc\theta = \frac{1}{\sin\theta}.
FunctionDefinitionPeriodDomain (gaps)Range
sin θy-coord on unit circleall ℝ[−1, 1]
cos θx-coord on unit circleall ℝ[−1, 1]
tan θsin θ / cos θπθ ≠ π/2 + kπall ℝ
cot θcos θ / sin θπθ ≠ kπall ℝ
sec θ1 / cos θθ ≠ π/2 + kπ(−∞,−1] ∪ [1,∞)
csc θ1 / sin θθ ≠ kπ(−∞,−1] ∪ [1,∞)
The vertical asymptotes you see in the graphs of tan, cot, sec, csc are simply the places where the denominator (cos or sin) hits zero. Division-by-zero on the unit circle becomes a vertical line on the graph.

Graphs of Sine and Cosine

If you start a stopwatch and watch the y-coordinate of a point spinning around the unit circle, you trace out the graph of y=sinty = \sin t. If you watch the x-coordinate, you trace out y=costy = \cos t. The animation below makes this concrete.

How the Circle Becomes a Wave

On the left, a point moves around the unit circle at constant angular speed. On the right, its height is unrolled along time — that is exactly the graph of sin(t).

0unit circley = sin(t)
t = 0.00 rad

From this picture, a few facts are visible:

  • Both sin\sin and cos\cos oscillate between 1-1 and 11.
  • They have the same shape but cosine is shifted left by π/2\pi/2: cosθ=sin(θ+π2)\cos\theta = \sin\bigl(\theta + \tfrac{\pi}{2}\bigr).
  • Sine is odd: sin(θ)=sinθ\sin(-\theta) = -\sin\theta. Cosine is even: cos(θ)=cosθ\cos(-\theta) = \cos\theta. (Geometrically: flipping the unit circle over the x-axis sends y to −y but leaves x alone.)

The Four Knobs: A · sin(B(x − C)) + D

Every sine wave that nature can produce — the pressure variation of a pure tone, the voltage at a wall outlet, the height of the tide at a port — fits the same template:

y=Asin ⁣(B(xC))+D.y = A\,\sin\!\bigl(B(x - C)\bigr) + D.

Each letter has a single physical meaning. The order matters because each knob acts on a different axis:

ParameterRoleEffect on graph
Aamplitudevertical stretch — peak-to-mean distance
Bangular frequencyhorizontal squeeze — period T = 2π/B
Cphase shiftslide left/right — peak moves to x = C + π/(2B)
Dvertical offsetslide whole wave up/down — midline y = D

Build a Sinusoidal Wave: y = A · sin(B(x − C)) + D

Each slider changes a single behaviour: vertical stretch, horizontal squeeze, slide left/right, slide up/down. This is the 4-parameter language of every wave on Earth.

-2π-1π0A = 1.00T = 6.283

Period vs frequency vs angular frequency. Three different numbers measure the same thing in different units:

  • Period TT — how many secondsper cycle. Units: s/cycle.
  • Frequency f=1/Tf = 1/T — how many cycles per second. Units: Hz.
  • Angular frequency ω=2πf=2π/T\omega = 2\pi f = 2\pi/T — how many radians per second. This is the BB in our formula.

A 440 Hz musical "A" has f=440f = 440, period T=1/4402.27T = 1/440 \approx 2.27 ms, angular frequency ω2765\omega \approx 2765 rad/s.


The Identities That Tie It Together

An identity is an equation that holds for every value of the variable, not just some. Trig has dozens, but four families are enough to derive the rest.

1. Pythagorean identities

Direct from x2+y2=1x^2 + y^2 = 1 on the unit circle:

sin2θ+cos2θ=1.\sin^2\theta + \cos^2\theta = 1.

Dividing through by cos2θ\cos^2\theta and by sin2θ\sin^2\theta gives two siblings:

1+tan2θ=sec2θ,1+cot2θ=csc2θ.1 + \tan^2\theta = \sec^2\theta, \qquad 1 + \cot^2\theta = \csc^2\theta.

2. Even / odd identities

sin(θ)=sinθ,cos(θ)=cosθ,tan(θ)=tanθ.\sin(-\theta) = -\sin\theta, \qquad \cos(-\theta) = \cos\theta, \qquad \tan(-\theta) = -\tan\theta.

3. Co-function (complementary-angle) identities

sin ⁣(π2θ)=cosθ,cos ⁣(π2θ)=sinθ.\sin\!\bigl(\tfrac{\pi}{2} - \theta\bigr) = \cos\theta, \qquad \cos\!\bigl(\tfrac{\pi}{2} - \theta\bigr) = \sin\theta.

4. Sum and difference formulas

The most useful identities of all. Memorize these two:

sin(α±β)=sinαcosβ±cosαsinβ,\sin(\alpha \pm \beta) = \sin\alpha\cos\beta \pm \cos\alpha\sin\beta,
cos(α±β)=cosαcosβsinαsinβ.\cos(\alpha \pm \beta) = \cos\alpha\cos\beta \mp \sin\alpha\sin\beta.

Plugging α=β=θ\alpha = \beta = \theta gives the double-angle formulas:

sin2θ=2sinθcosθ,cos2θ=cos2θsin2θ=12sin2θ=2cos2θ1.\sin 2\theta = 2\sin\theta\cos\theta, \qquad \cos 2\theta = \cos^2\theta - \sin^2\theta = 1 - 2\sin^2\theta = 2\cos^2\theta - 1.
📐 Worked example: simplify sin(75°) using a sum formula

We do not have 75° in the special-angles table. But 75° = 45° + 30°, and both of those are in the table. Use the sum formula:

sin(45+30)=sin45cos30+cos45sin30.\sin(45^\circ + 30^\circ) = \sin 45^\circ \cos 30^\circ + \cos 45^\circ \sin 30^\circ.

Plug in the table values:

=2232+2212=6+24.= \tfrac{\sqrt{2}}{2} \cdot \tfrac{\sqrt{3}}{2} + \tfrac{\sqrt{2}}{2} \cdot \tfrac{1}{2} = \tfrac{\sqrt{6} + \sqrt{2}}{4}.

Numerical check: 6+242.449+1.41440.9659\tfrac{\sqrt{6}+\sqrt{2}}{4} \approx \tfrac{2.449 + 1.414}{4} \approx 0.9659. And from a calculator sin750.9659\sin 75^\circ \approx 0.9659. ✓

That is the entire pleasure of identities: they let you reach values that look inaccessible by chaining together values you already know.


Modeling Periodic Phenomena

Whenever a quantity oscillates between two extremes over a fixed period, the four-knob template gives you a model with very little extra work. The recipe is:

  1. Find the midline: D=max+min2D = \tfrac{\max + \min}{2}.
  2. Find the amplitude: A=maxmin2A = \tfrac{\max - \min}{2}.
  3. Find the angular frequency: B=2πTB = \tfrac{2\pi}{T}, where TT is the observed period.
  4. Find the phase shift CC from where the peak (for cosine) or zero-crossing-going-up (for sine) actually occurs.
🌊 Worked example: model a tide

At a coastal town, high tide is 8 m, low tide is 2 m. High tide arrived at 03:00 today. The next high tide arrives at 15:24. Find a function for the water height h(t)h(t) in metres, with tt in hours from midnight.

Step 1 — midline. D=8+22=5D = \tfrac{8 + 2}{2} = 5 m.

Step 2 — amplitude. A=822=3A = \tfrac{8 - 2}{2} = 3 m.

Step 3 — period. Two consecutive high tides are 15:24 − 03:00 = 12.4 hours apart, so T=12.4T = 12.4 h. Therefore B=2π12.40.5067B = \tfrac{2\pi}{12.4} \approx 0.5067 rad/h.

Step 4 — phase. Cosine peaks at its argument = 0. We want the peak at t=3t = 3. So choose C=3C = 3. Putting it together:

h(t)=3cos ⁣(0.5067(t3))+5metres.h(t) = 3\,\cos\!\bigl(0.5067 (t - 3)\bigr) + 5 \quad\text{metres}.

Quick sanity check at t=3t = 3: h(3)=3cos0+5=8h(3) = 3\cos 0 + 5 = 8. ✓ At t=9.2t = 9.2 (low tide, halfway between): h3cosπ+5=2h \approx 3\cos\pi + 5 = 2. ✓

Pattern to remember: the shape of the wave (sine vs cosine, which phase) is always a stylistic choice. The four numbers A, B, C, D carry all the physics. Find them, write the formula, you are done.

Sums of Sines: A Peek at Fourier

A single sine wave is monotonous. Reality — a violin note, a spoken vowel, a radio signal — is more complicated. The Fourier theorem says something astonishing: any periodic function (under very mild conditions) is a sum of sines and cosines with different amplitudes and frequencies.

Adding Sine Waves — a peek at Fourier

A sum of three sines with different amplitudes and frequencies. Any periodic signal — your voice, a violin, a heartbeat — is a sum like this with many more terms.

harmonic 1
harmonic 2
harmonic 3

Play with the sliders. Three sine waves are already enough to make complex, irregular-looking shapes. A full violin tone uses dozens. An MP3 file is basically a list of amplitudes for thousands of these sine waves. The whole field of signal processing exists to find clever ways of computing and storing those amplitudes.

We will revisit this idea after we have derivatives and integrals (Chapter 8). For now, the takeaway is just: sin and cos are the atoms of periodic motion.

Computing with Python and NumPy

Now let us see how all this looks in code. We start with plain Python to keep the algorithm visible, then move to NumPy where vectorization makes everything fast. Both libraries use the radian convention — feeding them degrees by mistake is one of the most common bugs in scientific Python.

1. Plain Python: building a sine table by hand

Sine values at the five special angles — plain Python loop
🐍python
1Import math

Standard library only. math.sin and math.cos work on individual floats and expect the angle in radians. We use math.pi for an accurate value of π (3.141592653589793).

4Build the list of (angle, label) pairs

Each entry is a tuple: the numeric angle in radians plus a human label. Storing them together keeps the loop body simple — no need to maintain two parallel lists.

EXECUTION STATE
special_angles = [(0.0,'0'), (π/6,'pi/6'), …] // 5 (float, str) tuples
len(special_angles) = 5
12Print the header row

f-string with right-aligned columns of width 8 / 8 / 10 / 10. Cosmetic, but it makes the output legible.

13Print a separator

Forty-six dashes — chosen so the bar is the same width as the header. Pure presentation.

15Loop over the five angles

Python tuple-unpacking: each iteration binds theta to the numeric radian value and label to the string. We then compute sin and cos and print one row.

LOOP TRACE · 5 iterations
i=0 theta=0, label='0'
theta = 0.000000
s = math.sin(0) = 0.000000
c = math.cos(0) = 1.000000
i=1 theta=π/6, label='pi/6'
theta = 0.523599
s = math.sin(π/6) = 0.500000
c = math.cos(π/6) = 0.866025
i=2 theta=π/4, label='pi/4'
theta = 0.785398
s = math.sin(π/4) = 0.707107
c = math.cos(π/4) = 0.707107
i=3 theta=π/3, label='pi/3'
theta = 1.047198
s = math.sin(π/3) = 0.866025
c = math.cos(π/3) = 0.500000
i=4 theta=π/2, label='pi/2'
theta = 1.570796
s = math.sin(π/2) = 1.000000
c = math.cos(π/2) = 0.000000
16math.sin(theta) — the actual computation

Behind the scenes, math.sin uses the CORDIC algorithm or a polynomial approximation. The crucial point: the argument is interpreted as RADIANS. If you wanted to pass 90 degrees, you would have to write math.sin(math.radians(90)).

17math.cos(theta) — companion

Same deal as sine, returning the x-coordinate on the unit circle. Notice that cos(π/2) prints as 6.12e-17, not exactly 0 — that is float-precision dust, not a bug. The true value is 0 but the IEEE-754 representation of π/2 is slightly off.

18Print one row of the table

Right-aligned formatting: width 8 for the label, width 8 with 4 decimals for the radian value, width 10 with 6 decimals for sin and cos. Aligning columns is what turns numbers into a usable table.

10 lines without explanation
1import math
2
3# Five "special" angles in radians, paired with their fraction-of-pi labels.
4special_angles = [
5    (0.0,            "0"),
6    (math.pi / 6,    "pi/6"),
7    (math.pi / 4,    "pi/4"),
8    (math.pi / 3,    "pi/3"),
9    (math.pi / 2,    "pi/2"),
10]
11
12print(f"{'angle':>8} | {'rad':>8} | {'sin':>10} | {'cos':>10}")
13print("-" * 46)
14
15for theta, label in special_angles:
16    s = math.sin(theta)
17    c = math.cos(theta)
18    print(f"{label:>8} | {theta:>8.4f} | {s:>10.6f} | {c:>10.6f}")

The expected output is exactly the textbook table:

   angle |      rad |        sin |        cos
----------------------------------------------
       0 |   0.0000 |   0.000000 |   1.000000
    pi/6 |   0.5236 |   0.500000 |   0.866025
    pi/4 |   0.7854 |   0.707107 |   0.707107
    pi/3 |   1.0472 |   0.866025 |   0.500000
    pi/2 |   1.5708 |   1.000000 |   0.000000

2. NumPy: vectorized version for plotting

Plain Python is great for one value at a time. For the thousands of points you need to draw a sine wave, NumPy is 100× faster because the whole loop runs in compiled C under the hood.

Sampling and plotting a sinusoid the NumPy way
🐍python
1Import NumPy

NumPy provides np.ndarray (a fast, homogeneous array) plus vectorized math operations. The convention `import numpy as np` is universal — every tutorial, every paper, every notebook uses np.

2Import matplotlib

matplotlib.pyplot is the de-facto plotting library. `plt` is the universally accepted alias. We will use it to draw the wave.

5np.linspace(start, stop, num)

Builds an array of 500 numbers, evenly spaced from 0 up to and INCLUDING 4π. Including the endpoint matters for clean plotting. The spacing is (4π - 0) / 499 ≈ 0.02519 rad — about 1.44°.

EXECUTION STATE
t.shape = (500,)
t[0] = 0.0
t[-1] = 12.566 (≈ 4π)
t[1] - t[0] = 0.025183 (Δt)
8Wave parameters as plain floats

Python multiple assignment: A becomes 2.0, B becomes 1.5, etc. These are the four 'knobs' from the section. With these values, amplitude is 2, period is 2π/1.5 ≈ 4.19, the wave is shifted right by 0.5 and up by 0.3.

EXECUTION STATE
A = 2.0
B = 1.5
C = 0.5
D = 0.3
11y = A * np.sin(B * (t - C)) + D — vectorized!

This single line creates an array y with the same shape as t. NumPy broadcasts the scalar parameters across all 500 entries. There is no Python for-loop — the multiplication, subtraction, np.sin, addition each loop in optimized C. For 500 points the speed-up is invisible; for 5 million points it is the difference between 5 milliseconds and 5 seconds.

EXECUTION STATE
(t - C).shape = (500,) — same shape as t
B * (t - C) = rescaled inputs to sin
y.shape = (500,)
y.min() = ≈ -1.700 (= D - A)
y.max() = ≈ 2.300 (= D + A)
14Compute period from B

Direct application of T = 2π/B. With B = 1.5 you get T = 2π/1.5 ≈ 4.18879 rad. This is the horizontal distance from one peak to the next on the plot.

EXECUTION STATE
T = 4.188790
15Frequency = 1 / period

f = 1/T = 0.23873… If t were time in seconds, this would be 0.2387 Hz — about one cycle every four seconds.

EXECUTION STATE
f = 0.238732
16Print the diagnostics

Always sanity-check derived numbers before plotting. If T came out negative or zero you would catch it here instead of staring at a blank plot wondering what is wrong.

19plt.subplots — create figure and axes

Returns a Figure (the whole canvas) and an Axes (one plot area inside it). The `figsize=(8, 3)` is in inches at 100 dpi by default, so the saved PNG would be 800×300 px. A wider-than-tall ratio is what you want for waves.

20ax.plot(t, y, ...) — draw the line

Plots y against t with a cyan stroke 2.2 pixels wide. The colour string is a hex code; you can also use named colours like 'red' or matplotlib codes like 'C0'. linewidth is one of dozens of kwargs you can pass.

21ax.axhline — the midline

Draws a horizontal line at y = D (here, 0.3). This visually confirms the vertical-offset knob: the wave should oscillate symmetrically above and below this dashed line.

22set_xlabel — name the x-axis

Always label your axes. 'radians' is the unit because we built t with np.linspace in radians. If you forget the unit, a future reader cannot tell if the period is in radians, seconds, or microseconds.

23set_ylabel and set_title

Same idea for the y-axis label and the figure title. The title is the formula being plotted, written in plain text so it shows up correctly even without LaTeX rendering.

25ax.grid(alpha=0.3) — light gridlines

alpha is the opacity: 1.0 is opaque, 0.0 is invisible. 0.3 produces a subtle grid that helps the eye read off coordinates without dominating the plot.

26plt.show() — render

In a script this pops up a window. In a Jupyter notebook with `%matplotlib inline`, it embeds the figure. In a saved-figure workflow you replace this with `fig.savefig('wave.png', dpi=150)`.

11 lines without explanation
1import numpy as np
2import matplotlib.pyplot as plt
3
4# 1) Build 500 evenly spaced sample points over two full periods (0 to 4π).
5t = np.linspace(0.0, 4.0 * np.pi, 500)
6
7# 2) Choose the four wave knobs: amplitude, angular frequency, phase, offset.
8A, B, C, D = 2.0, 1.5, 0.5, 0.3
9
10# 3) Vectorized formula — runs once on the WHOLE array, no Python loop.
11y = A * np.sin(B * (t - C)) + D
12
13# 4) Compute period and frequency from B.
14T = 2.0 * np.pi / B
15f = 1.0 / T
16print(f"period T = {T:.4f} s, frequency f = {f:.4f} Hz")
17
18# 5) Quick plot — set up a clean figure.
19fig, ax = plt.subplots(figsize=(8, 3))
20ax.plot(t, y, color="#22d3ee", linewidth=2.2)
21ax.axhline(D, color="#a78bfa", linestyle="--", linewidth=1)
22ax.set_xlabel("t (radians)")
23ax.set_ylabel("y")
24ax.set_title("y = A sin(B(t-C)) + D")
25ax.grid(alpha=0.3)
26plt.show()

Expected console output:

period T = 4.1888 s, frequency f = 0.2387 Hz
Degrees vs radians — the single biggest trig bug. Both math.sinmath.sin and np.sinnp.sin expect radians. If you write np.sin(90)np.sin(90) expecting 1, you actually get 0.894\approx 0.894 — the sine of 90 radians, which is more than 14 full turns around the circle. Always wrap with np.deg2radnp.deg2rad if your data is in degrees.

3. Verifying the Pythagorean identity numerically

Sanity-check sin²θ + cos²θ = 1 over a million angles
🐍python
1Import NumPy

Same convention as before. The rest of the script lives in NumPy.

4Create a seeded random generator

np.random.default_rng(seed=42) returns a Generator object. The seed makes the run reproducible — every reader of this code will get exactly the same 'random' angles. Without a seed you get different numbers every run, which is useless for verification.

EXECUTION STATE
rng = <Generator(PCG64) at 0x...>
5Draw 1,000,000 angles uniformly

rng.uniform(low, high, size) returns an array of 1 million floats, each drawn independently and uniformly from [-10π, 10π]. The wide range — about 100 radians on each side — is a stress test: any periodicity bug would show up at extreme angles. Note the underscore-separated integer literal 1_000_000 (Python 3.6+); easier to read than 1000000.

EXECUTION STATE
theta.shape = (1000000,)
theta.dtype = float64
theta.min() = ≈ -31.41
theta.max() = ≈ +31.41
8Compute sin² + cos² vectorized

Three independent vector operations: np.sin(theta) produces 1M sines, np.cos(theta) produces 1M cosines, then squaring and adding produces the LHS of the identity. NumPy chains them efficiently — only one Python statement, six C-loops under the hood. On a laptop this takes about 30 ms.

EXECUTION STATE
lhs.shape = (1000000,)
lhs[0] = 1.0000000000000002 (note the floating dust)
11Find the worst-case error

np.abs(lhs - 1.0) is a vector of how far each entry is from 1. np.max picks the worst one. We expect a tiny number — single-precision dust around 1e-16 (machine epsilon for float64).

EXECUTION STATE
max_error = ≈ 2.22e-16
12Average error

np.mean gives the average absolute deviation. We expect this to be even smaller than the max, because most angles land in well-conditioned regions. Reporting both numbers is good hygiene — the max tells you the worst case, the mean tells you the typical case.

EXECUTION STATE
mean_error = ≈ 5.55e-17
13Print the diagnostics

Scientific notation with 3 significant figures. The result should be ~1e-16, which is machine epsilon for IEEE-754 float64. That confirms: the Pythagorean identity holds for every angle, up to round-off. The identity is not an approximation — it is exact mathematics, and NumPy is honest about telling you it's only off by a single least-significant bit.

7 lines without explanation
1import numpy as np
2
3# Generate one million random angles in the range [-10π, 10π].
4rng = np.random.default_rng(seed=42)
5theta = rng.uniform(-10.0 * np.pi, 10.0 * np.pi, size=1_000_000)
6
7# Pythagorean identity, vectorized.
8lhs = np.sin(theta) ** 2 + np.cos(theta) ** 2
9
10# How far from 1 do we ever get?
11max_error = np.max(np.abs(lhs - 1.0))
12mean_error = np.mean(np.abs(lhs - 1.0))
13print(f"max absolute error  = {max_error:.3e}")
14print(f"mean absolute error = {mean_error:.3e}")

Expected output:

max absolute error  = 2.220e-16
mean absolute error = 5.551e-17

Why this matters

Numerical verification is not a substitute for proof, but it is the fastest sanity check available. If your identity fails by 1e-3 on a real-world input, you have a bug. If it fails by 1e-16, you have machine epsilon — that is the noise floor of float64, and there is nothing more accurate without going to 128-bit floats.

Calculus Preview: Why sin and cos Are Magical

We have not done calculus yet, but you should know what makes sin and cos uniquely beautiful before we get there.

The miracle of trigonometry: ddθsinθ=cosθ,ddθcosθ=sinθ.\dfrac{d}{d\theta}\sin\theta = \cos\theta, \quad \dfrac{d}{d\theta}\cos\theta = -\sin\theta.

That is to say: the rate of change of sin is cos, and the rate of change of cos is −sin. This is the only pair of functions (besides exponentials) that is essentially its own derivative. And this is precisely why every linear differential equation describing oscillation — a mass on a spring, a pendulum, an LC circuit, a photon — has sines and cosines as solutions.

This derivative rule only works when θ is in radians. That is the deepest reason we adopted radians as the "real" angle unit. Calculus picks the radian; we do not have a choice.

We will derive both of these formulas from the limit definition in Chapter 5. The key ingredient turns out to be a special limit you will meet in Chapter 2: limh0sinhh=1\lim_{h \to 0} \tfrac{\sin h}{h} = 1 — the statement that for small angles, sine and angle are the same number.


Summary

  1. Definition. On the unit circle a point at angle θ has coordinates (cosθ,sinθ)(\cos\theta, \sin\theta). Every trig function is a ratio or reciprocal built from these two.
  2. Radians. Angle = arc length on the unit circle. One full turn is 2π2\pi radians. All of calculus assumes this unit.
  3. Special angles. 0, π/6, π/4, π/3, π/2 give the table you should know by heart.
  4. Graphs. y=Asin(B(xC))+Dy = A\sin(B(x-C)) + D covers every sinusoid you will ever see: amplitude A, period 2π/B, phase shift C, midline D.
  5. Identities. Pythagorean (sin2+cos2=1\sin^2 + \cos^2 = 1), even/odd, complementary, sum/difference, double-angle. Each is a tool for converting one form to a more useful one.
  6. Modeling. Periodic phenomena follow the four-knob template; find midline, amplitude, period, phase from the data.
  7. Fourier hint. Every periodic signal is a sum of sines. We will formalise this much later.
  8. Code. math.sinmath.sin and np.sinnp.sin both expect radians. Mixing units silently is the #1 trig bug.

Exercises

Conceptual

  1. Explain in one sentence, using the unit-circle picture, why sin(π+θ)=sinθ\sin(\pi + \theta) = -\sin\theta.
  2. Why is tan(π/2)\tan(\pi/2) undefined, but sin(π/2)\sin(\pi/2) is perfectly fine? Answer with coordinates, not just "division by zero".
  3. Without computing, decide whether cos(5π/3)\cos(5\pi/3) is positive or negative. Which quadrant?

Computational

  1. Convert 210° to radians and find sin(210)\sin(210^\circ) and cos(210)\cos(210^\circ) exactly.
  2. Find amplitude, period, phase shift, and midline of y=3cos ⁣(π2(x+1))+4y = -3\cos\!\bigl(\tfrac{\pi}{2}(x + 1)\bigr) + 4.
  3. Use the sum formula to find cos(15)\cos(15^\circ) exactly. Hint: 15 = 45 − 30.
  4. Solve 2sinθ1=02\sin\theta - 1 = 0 for all θ[0,2π)\theta \in [0, 2\pi).

Modeling

  1. A Ferris wheel of radius 20 m turns once every 90 s. A passenger starts at the bottom (3 m above ground). Write a function for the passenger's height vs time. What is the height at t=30t = 30 s?
  2. A 60 Hz alternating-current outlet supplies voltage V(t)=170sin(120πt)V(t) = 170\sin(120\pi t). What are amplitude, period, and frequency? Why is "120π" the angular frequency for a 60 Hz signal?
  3. Daylight in Boston ranges from 9.0 h (Dec 21) to 15.3 h (Jun 21). Build a sinusoidal model L(d)L(d) for daylight hours as a function of day-of-year dd. How many hours of daylight on March 21 (day 80)?

Programming

  1. Write a Python function degreestoradians(d)degrees_to_radians(d) from scratch (no math.radiansmath.radians). Verify with at least three test angles.
  2. Plot f(x)=sin(x)+13sin(3x)+15sin(5x)f(x) = \sin(x) + \tfrac{1}{3}\sin(3x) + \tfrac{1}{5}\sin(5x) on [π,π][-\pi, \pi]. What familiar shape does this look like? (Hint: it converges to a square wave.)
  3. Vectorize the Pythagorean-identity check from this section to also verify 1+tan2=sec21 + \tan^2 = \sec^2. Be careful around θ=π/2+kπ\theta = \pi/2 + k\pi where tan blows up.

In the next section we will invert these functions — arcsin, arccos, arctan — to answer the reverse question: "given a sine value, what angle produced it?" That requires choosing a single branch and is the cousin of the multi-valued conversation we began here.

Loading comments...