Plotting · trigonometry
Graphing sin x cos x: Period, Amplitude and Sampling
The product sin x cos x looks like it needs a careful plot, but a one-line identity turns it into a familiar curve. Using sin 2x = 2 sin x cos x, the product equals ½ sin 2x. Graphing it therefore means drawing a sine wave with half the usual height, and twice the usual frequency. This page works through the simplification, lists the points that anchor the sketch, and then shows how to sample and draw the curve in a script. It is part of the plotting material under Data and files.
Simplify first
Because sin x cos x = ½ sin 2x, the amplitude is ½. The curve oscillates between −0.5 and 0.5, never reaching 1. The factor 2 inside the sine compresses the horizontal axis: sin 2x completes a cycle when 2x advances by 2π, so the period is π, half that of the plain sine. In summary: amplitude ½, period π, no horizontal shift, and the curve passes through the origin.
A common error is to read the product as having amplitude 1 because each factor does. Both factors reach 1 at different places, and they are never at their maximum together. Checking one value avoids the slip: at x = π/4 both sin and cos equal √2/2 ≈ 0.7071, and the product is 0.5, exactly the maximum.
Key points
Within one period from 0 to π, four points fix the shape:
| x | sin x cos x |
|---|---|
| 0 | 0 |
| π/4 | 0.5 |
| π/2 | 0 |
| 3π/4 | −0.5 |
| π | 0 |
The zeros fall at multiples of π/2, where one of the two factors is zero. The maxima of 0.5 fall at π/4 plus multiples of π, and the minima of −0.5 at 3π/4 plus multiples of π. Because ½ sin 2x is an odd function, the plot is symmetric through the origin: replacing x with −x flips the sign.
Sampling and drawing
A script samples the function at a set of x values and joins the points. The spacing decides how smooth the curve is. With a period of π, sampling from 0 to 2π covers two full periods. Using 201 points gives a step of 2π/200 ≈ 0.0314, about 100 points per period, which is smooth on screen. With only 9 points, a step of π/4, the curve would show the key points above and the line segments between them would look like a zigzag.
import numpy as np, matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 201)
y = np.sin(x) * np.cos(x)
plt.plot(x, y)
plt.plot(x, 0.5*np.sin(2*x), "--") # identity check, lies on top
plt.axhline(0, color="gray", lw=0.5)
plt.xlabel("x (radians)")
Plotting both forms is a useful habit. If the dashed curve does not sit exactly on the solid one, there is an error in one of the two expressions. The largest absolute difference between the arrays should be of order 10⁻¹⁶, which is rounding error.
Axis labels in multiples of π
Radian values like 1.5708 are poor tick labels. Place ticks at multiples of π/2 and label them with text such as 0, π/2, π, 3π/2, 2π. Most plotting tools allow a list of tick positions and a matching list of labels. With the horizontal axis labelled this way, the zero crossings and extremes can be read straight off the figure.
Related ideas
The same method plots any product of sinusoids: sin a·x times sin b·x is half the difference of two cosines with frequencies a − b and a + b, so beats appear when a and b are close. For choosing and presenting plots in general, see data visualization, and for moving the numbers into a dedicated package, see graphing results in SigmaPlot. Related window and kernel shapes are covered under the sinc function.