Graphs of Trigonometric Functions: All Six, and How to Sketch Them

Updated 20 min read Intermediate Baca dalam Bahasa Indonesia

Geometry Algebra Computing Python JavaScript

Quick answer

Each trigonometric function has a graph read off the unit circle: sine and cosine are waves between -1 and 1 that repeat every 360^\circ, tangent and cotangent repeat every 180^\circ with vertical asymptotes, and secant and cosecant are U-shaped branches that never lie between -1 and 1. The equation y=a f(b(x-c))+d stretches the graph by a, divides the period by b, shifts it right by c and up by d, and a sketch needs only the period, the shift and five key points.

Key takeaways

  • All six graphs come from one picture, the unit circle: the point at the angle θ gives \sinθ and \cosθ, and the ray through it cuts the lines x=1 and y=1 at lengths \tanθ, \secθ, \cotθ and \cscθ. The asymptotes appear where the ray is parallel to one of those lines.
  • The tangent has vertical asymptotes at x=90^\circ+180^\circ n, where \cos x=0, and repeats every 180^\circ, not 360^\circ, because half a turn changes the signs of the sine and the cosine together. It has no amplitude: its range is every real number.
  • Secant, cosecant and cotangent are drawn from the cosine, sine and tangent by taking reciprocals: an asymptote wherever the base is 0, a tip wherever the base is 1 or -1, and values that never fall between -1 and 1 for secant and cosecant.
  • In y=a f(b(x-c))+d the period is the parent period divided by |b|, the shift is c, and d lifts the graph. If the equation is written y=a f(bx-B)+d, the shift is B/b, not B: the most common error with these graphs.
  • A wave is read from its picture in three numbers: d=(\max+\min)/(2), a=(\max-\min)/(2), and the period P from two successive peaks, with b=(360^\circ)/(P); a cosine is then shifted by the x of a peak, and a sine by a quarter of a period less.
  • Two waves of the same frequency add up to one wave; waves of different frequencies add up to a wave that is not a sine, repeating every (360^\circ)/(\gcd) if the frequencies are whole numbers and never if their ratio is irrational. A sine wave of known period is fitted to measurements by least squares, which is a linear problem in \sin, \cos and a constant.

How does the unit circle give the graphs of all six trigonometric functions?

On the unit circle all six functions of an angle θ are lengths you can see: sine and cosine are the height and the width of the point, the tangent is the height at which the ray through the point meets the line x=1, and the cotangent is the distance at which it meets the line y=1. Put the point P at the angle θ on the circle of radius 1 (see the unit circle). Extend the ray from the centre through P until it meets the vertical line x=1. By similar triangles the height of the meeting point is (\sinθ)/(\cosθ)=\tanθ, and the length of the ray up to it is (1)/(\cosθ)=\secθ. Do the same with the horizontal line y=1: the meeting point is at x=\cotθ and the ray has length \cscθ.

A graph is what you get by letting θ turn and plotting one of these lengths against the angle. Because all six come from one picture, their features can be read from it. The ray is parallel to the line x=1 when θ=90^\circ, so it never meets it, and \tanθ and \secθ do not exist there. The ray is parallel to the line y=1 when θ=0^\circ and 180^\circ, and \cotθ and \cscθ do not exist. Those gaps are the vertical asymptotes. The sine and the cosine are shadows of a segment of length 1, so they never exceed 1, but the lines x=1 and y=1 are infinitely long, so the tangent and the cotangent can be any number.

The six functions of $\theta$ as lengths on the unit circle: $\sin\theta$ and $\cos\theta$ are the height and the width of the point; the ray through the point meets the line $x=1$ at the height $\tan\theta$, and its length up to that line is $\sec\theta$; it meets the line $y=1$ at the distance $\cot\theta$ along it, and its length up to that line is $\csc\theta$. Here $\theta=35^\circ$.

Why does the tangent graph have vertical asymptotes and repeat every 180°?

The graph of y=\tan x has a vertical asymptote at every x=90^\circ+180^\circ n, because \tan x=(\sin x)/(\cos x) and the cosine is zero there; between two asymptotes it rises from far below to far above, and the whole picture repeats every 180^\circ. Follow one branch, from -90^\circ to 90^\circ. At 0^\circ the sine is 0, so \tan0^\circ=0. As x grows towards 90^\circ the sine approaches 1 and the cosine approaches 0 from the positive side, so the quotient grows without limit: the graph shoots up along the asymptote. Just after 90^\circ the cosine is a small negative number while the sine is still near 1, so the tangent comes in from far below, passes through 0 at 180^\circ, and the next branch begins.

The period is 180^\circ and not 360^\circ because half a turn sends the point (\cos x,\sin x) to (-\cos x,-\sin x): both signs change and the quotient does not notice, \tan(x+180^\circ)=\tan x. The other facts follow from the quotient. \tan45^\circ=1, since the sine and cosine are equal. \tan(-x)=-\tan x, so the graph is unchanged by a half turn about the origin. The tangent never has a highest or lowest point and rises on every branch, so its range is all real numbers and it has no amplitude. Its slope at 0 is 1 when x is in radians, which is why \tan x≈ x for small angles (the derivative is \sec^2x, see the derivatives of the other four functions). In radians the asymptotes are at (π)/(2)+π n and the period is π.

The graph of $y=\tan x$. It is undefined at $-90^\circ$, $90^\circ$, $270^\circ$, and so on (dashed lines: the vertical asymptotes), rises from far below to far above between two of them, passes through $(0^\circ,0)$ and $(45^\circ,1)$, and is the same picture again $180^\circ$ later.

How do you draw secant, cosecant and cotangent from cosine, sine and tangent?

To draw the secant, cosecant or cotangent, draw the cosine, sine or tangent faintly first and take reciprocals: an asymptote wherever the base function is 0, a tip wherever it is 1 or -1, and in between a curve that is far from the axis, because 1/y is large when y is small. For the secant, with \sec x=(1)/(\cos x):

  1. Sketch y=\cos x lightly.
  2. Draw a dashed vertical asymptote at every zero of the cosine: 90^\circ, 270^\circ, and so on.
  3. Mark the points where the cosine is 1 or -1 (its peaks and troughs). The secant has the same value there: (0^\circ,1), (180^\circ,-1), (360^\circ,1).
  4. From each of these points draw a U-shaped branch that runs away from the axis towards the two nearest asymptotes: opening upwards where the cosine is positive and downwards where it is negative.
  5. Check: the secant has the same sign as the cosine, and it never takes a value between -1 and 1.

The cosecant is the same with the sine: asymptotes at 0^\circ, 180^\circ, 360^\circ, tips at (90^\circ,1) and (270^\circ,-1). The cotangent is (1)/(\tan x)=(\cos x)/(\sin x): asymptotes where the tangent is 0 (at 180^\circ n), zeros where the tangent is undefined (90^\circ+180^\circ n), and it falls from far above to far below on every branch. It is the tangent reflected and shifted: \cot x=-\tan(x-90^\circ).

The secant (solid) drawn from the cosine (dashed). Where $\cos x=0$ the secant has asymptotes, at $90^\circ$ and $270^\circ$; where $\cos x$ is $1$ or $-1$ the secant touches the same height ($0^\circ$, $180^\circ$, $360^\circ$); and it never lies between $-1$ and $1$.

What are the period, domain, range and symmetry of each of the six graphs?

The six graphs differ in four things you can read from the table: the period (360^\circ for sine, cosine, secant and cosecant and 180^\circ for tangent and cotangent), the places where the function does not exist, the range, and where it is zero. In the table n is any whole number; the radian values of the periods are in brackets. Printed from the same data the checker compared with a scan of the graphs.

FunctionPeriodDomainRangeZerosAsymptotes
y=\sin x360^\circ (2π)all real numbers-1\le y\le1x=180^\circ nnone
y=\cos x360^\circ (2π)all real numbers-1\le y\le1x=90^\circ+180^\circ nnone
y=\tan x180^\circ (π)x\ne 90^\circ+180^\circ nall real numbersx=180^\circ nx=90^\circ+180^\circ n
y=\csc x360^\circ (2π)x\ne 180^\circ ny\le-1 or y\ge1nonex=180^\circ n
y=\sec x360^\circ (2π)x\ne 90^\circ+180^\circ ny\le-1 or y\ge1nonex=90^\circ+180^\circ n
y=\cot x180^\circ (π)x\ne 180^\circ nall real numbersx=90^\circ+180^\circ nx=180^\circ n

Symmetry. Cosine and secant are even: \cos(-x)=\cos x, so the graph is its own mirror image in the y-axis. Sine, tangent, cosecant and cotangent are odd: f(-x)=-f(x), so a half turn about the origin leaves the graph unchanged. Pick a function below, move the point along its graph, and read all of this in degrees or in radians.

Interactive: the graphs of the six trigonometric functions

Pick sine, cosine, tangent, cosecant, secant or cotangent, move a point along its graph, and read its period, domain, range, symmetry, zeros and asymptotes in degrees or radians.

How do a, b, c and d change the graph of any trigonometric function?

Any of the six graphs can be stretched and moved with y=a f(b(x-c))+d: a stretches it vertically (and flips it if a is negative), b squeezes it horizontally so that the period is the parent's period divided by |b|, c moves it to the right by c, and d lifts it by d. The four numbers act on different things, so they can be read off one at a time:

  • a, vertical stretch. For a sine or cosine, |a| is the amplitude, the distance from the midline to a peak. Tangent, cotangent, secant and cosecant have no amplitude (they are unbounded or have no peaks); a stretches them, and for the secant and cosecant the tips of the U-shapes are at d±|a|.
  • b, horizontal squeeze. The period is (360^\circ)/(|b|) for sine, cosine, secant and cosecant and (180^\circ)/(|b|) for tangent and cotangent (in radians (2π)/(|b|) and (π)/(|b|)). The asymptotes of a tangent are (180^\circ)/(|b|) apart. A negative b mirrors the graph in the y-axis; use \sin(-u)=-\sin u and \cos(-u)=\cos u to make b positive first.
  • c, shift. The graph moves right by c (left if c is negative): every special point of the parent, at u=b(x-c), moves to x=c+u/b. The asymptotes of a tangent are at x=c+(90^\circ+180^\circ n)/(b).
  • d, lift. The whole graph moves up by d; the midline of a wave is y=d. The vertical asymptotes do not move.

Bx minus B. Equations are often written y=a f(bx-B)+d. Factor out b: bx-B=b\left(x-B/b\right), so the shift is B/b, not B. For y=\sin(2x-60^\circ) the graph moves 30^\circ to the right, not 60^\circ. For example y=\tan2x has period 90^\circ and asymptotes at ±45^\circ, ±135^\circ, and y=2\cosx/2-1 has amplitude 2, midline y=-1 and period 720^\circ. Try all four numbers on any of the six functions below.

Interactive: a, b, c and d for any trigonometric graph

Stretch, squeeze, shift and lift the graph of any of the six functions with y = a f(b(x − c)) + d, with the parent drawn faintly, the asymptotes, the points to plot and the equation in both forms.

How do you sketch y = a sin(bx − B) + d by hand, and a tangent too?

To sketch a sine or cosine graph, find the period and the start of one cycle, mark five points a quarter of a period apart, give them the heights midline, peak, midline, trough, midline, and join them with a smooth wave. For y=a\sin(bx-B)+d:

  1. Period. P=(360^\circ)/(b).
  2. Start. The cycle starts where bx-B=0, so at x=B/b.
  3. Five points. x=B/b, B/b+P/4, B/b+P/2, B/b+(3P)/(4), B/b+P.
  4. Heights. For a positive a and a sine: d, d+a, d, d-a, d. (A cosine starts at the peak: d+a, d, d-a, d, d+a. A negative a swaps peak and trough.)
  5. Join the points with a smooth curve, flat at the peaks and troughs and steepest at the midline, and repeat the cycle in both directions.

Example. y=3\sin(2x-60^\circ)+1. The period is (360^\circ)/(2)=180^\circ, the cycle starts at x=(60^\circ)/(2)=30^\circ, the quarter points are 30^\circ, 75^\circ, 120^\circ, 165^\circ, 210^\circ and the heights are 1, 4, 1, -2, 1.

The graph of $y=3\sin(2x-60^\circ)+1$. One cycle starts where $2x-60^\circ=0$, that is at $x=30^\circ$, lasts $180^\circ$, and is drawn through five points a quarter of a period apart, at the heights $1,\ 4,\ 1,\ -2,\ 1$. The dashed curve is the parent $\sin x$.

A tangent is sketched from its asymptotes and three points. For y=a\tan(b(x-c))+d the period is (180^\circ)/(|b|); put two neighbouring asymptotes at x=c±(90^\circ)/(b), the graph crosses the line y=d halfway between them at x=c, and a quarter of the way in from each asymptote, at x=c±(45^\circ)/(b), it is at y=d± a (because \tan45^\circ=1). Then draw the branch through these three points rising towards both asymptotes, and repeat it. For y=2\tanx/2: the period is 360^\circ, the asymptotes are at ±180^\circ, the crossing is at the origin and the points (±90^\circ,±2) guide the curve.

The graph of $y=2\tan\frac{x}{2}$: the period is $\frac{180^\circ}{1/2}=360^\circ$, the asymptotes are at $x=\pm180^\circ$, the graph crosses at $0^\circ$, and at a quarter of the way to an asymptote, $x=\pm90^\circ$, it is at $y=\pm2$ (because $\tan45^\circ=1$ and $a=2$).

How do you find the equation of a trigonometric graph from its picture?

To write the equation of a sine or cosine graph, read the midline and the amplitude from its highest and lowest values, the period from two successive peaks, and the shift from the position of a peak.

  1. Midline and amplitude. d=(\max+\min)/(2) and a=(\max-\min)/(2).
  2. Period. P is the distance between two successive peaks (or twice the distance from a peak to the next trough). Then b=(360^\circ)/(P), or (2π)/(P) when x is a time and the argument is in radians.
  3. Shift. Choose the cosine and let c be the x of a peak, since \cos0=1. Or choose the sine and let c be the x of a peak minus P/4.
  4. Check the equation at one more point.

A tide. In the picture the water is highest, 2.9 m, at 3 h and at 15.4 h, and lowest, 0.7 m. Then d=1.8, a=1.1, P=15.4-3=12.4 h and y=1.1\cos\left((2π)/(12.4)(t-3)\right)+1.8; as a sine it is y=1.1\sin\left((2π)/(12.4)(t+0.1)\right)+1.8. The mains. The PLN supply is called 220 V, but that is its effective value; the wave reaches 220√2≈311 V. Peaks of 311.1 V at 5 ms and troughs at 15 ms give P=20 ms (that is 50 Hz) and v=311.1\sin\left((2π)/(20)t\right) with t in milliseconds. There is never only one right answer: a cosine can be a sine with another shift, adding a whole period to c changes nothing, and a negative a with a shift of half a period gives the same graph.

A tide (illustrative numbers): the water is highest, $2.9$ m, at $3$ h and again at $15.4$ h, and lowest, $0.7$ m. The midline is $\frac{2.9+0.7}{2}=1.8$ m, the amplitude $1.1$ m, the period $15.4-3=12.4$ h, so $y=1.1\cos\left(\frac{2\pi}{12.4}(t-3)\right)+1.8$.

Interactive: find the equation of a wave from its graph

Enter the highest and lowest values and the x of two successive peaks, and get a, d, the period and the sine and cosine equations, for a tide, the mains voltage or a wave of your own.

What happens when you add two sine waves, and is the sum still a sine wave?

Two sine waves of the same frequency add up to one sine wave, but waves of different frequencies add up to a graph that is not a sine wave; it repeats only if the ratio of the frequencies is a ratio of whole numbers. Write b for the number of cycles in 360^\circ, so that \sin bx has period (360^\circ)/(b).

  • Same frequency. A\sin bx+B\cos bx=R\sin(bx+φ) with R=√(A^2+B^2), one wave of the same period (see the single-wave form). Two waves of amplitudes A_1, A_2 with a phase difference φ give a wave of amplitude R=√(A_1^2+A_2^2+2A_1A_2\cosφ): between |A_1-A_2| (opposite) and A_1+A_2 (in step).
  • Whole-number frequencies. \sin2x+\sin3x repeats when both have finished whole cycles together: the period is (360^\circ)/(\gcd(2,3))=360^\circ. For \sin4x+\sin6x it is (360^\circ)/(2)=180^\circ. The shape is not a sine wave.
  • Irrational ratio. \sin x+\sin√2 x never repeats exactly, because no stretch of x holds a whole number of cycles of both. It comes close to repeating again and again, but it has no period.
  • Close frequencies: beats. \sin b_1x+\sin b_2x=2\cos(b_1-b_2)/(2)x \sin(b_1+b_2)/(2)x (a product-to-sum formula): a fast wave at the average frequency whose height swells and fades |b_1-b_2| times in 360^\circ. Two guitar strings at 440 Hz and 442 Hz are heard to swell 2 times a second, and tuning by ear means slowing the beats to nothing.

Choose two frequencies below and see the period of the sum, or the lack of one.

The sum $\sin10x+\sin11x$ over $0^\circ$ to $360^\circ$ (solid) is a fast wave whose height swells and fades inside the envelope $\pm2\cos\frac{x}{2}$ (dashed): $\sin10x+\sin11x=2\cos\frac{x}{2}\,\sin10.5x$. The loudness of two close notes does this, and the swelling is called a beat.

Interactive: adding two sine waves

Choose two frequencies, amplitudes and a phase and see when the sum repeats, when it never does (the ratio is irrational), and how close frequencies beat.

How do you fit a sine wave to measurements?

To fit a sine wave to measurements, choose the period from what you know about the cause, and then the other numbers come from a linear least-squares problem: y≈ A\sin bx+B\cos bx+D with b=(360^\circ)/(P). The unknown shift would make the problem hard, but the sum formula hides it in the products: a\sin(b(x-c))=(a\cos bc)\sin bx-(a\sin bc)\cos bx, so with A=a\cos bc and B=-a\sin bc the equation is linear in A, B and D. Least squares chooses them so that the sum of the squared errors, the vertical distances from each point to the wave, is as small as possible; that is a 3×3 linear system. Then a=√(A^2+B^2), d=D, c=-\frac\operatornameatan2(B,A)b, and c can be moved into one period by adding the period.

Example. Twelve monthly mean temperatures (illustrative) and the period 12 months give a≈9.77 ^\circC, d≈13.45 ^\circC, c≈4.09 months, so the warmest point is at x=c+P/4≈7.09, early in the seventh month. The measure of fit is R^2=1-(squared errors)/(squared spread of the data): here 0.996, so the wave explains 99.6\% of the variation. When the period is not known, try many periods and keep the best R^2: a wave of 0.6 times the right period explains only about 30\% of this data. A high R^2 says the wave describes these measurements, not that the cause is periodic.

Twelve monthly mean temperatures (illustrative, in $^\circ$C) and the least-squares wave of period $12$ months through them: $y\approx9.7716\sin\left(\frac{2\pi}{12}(x-4.0942)\right)+13.45$, with $R^2\approx0.9959$. The dashed line is the mean level.

Interactive: fit a sine wave to measurements

Fit the best wave of a chosen period to monthly temperatures, daylight or a tide by least squares, see the errors as red segments, and search for the period that explains the most.

How do you draw and fit trigonometric graphs in a program?

A program draws a tangent or secant by treating the asymptotes as gaps: it evaluates the function on a grid, writes nothing where the function does not exist or is huge, and starts a new line after every gap. Three details matter. The cosine of 90^\circ is not exactly 0 on a computer (6×10^-17), so test abs(cos) < 1e-12 rather than == 0 and the value 1.6×10^16 does not appear as a point on the graph. Convert degrees to radians. And never join two points on either side of an asymptote, however close, since the line between them is not part of the graph.

The programs print the tangent near 90^\circ (rising to 572.96 at 89.9^\circ, then undefined, then falling from -572.96) and then fit a wave of period 12 to the twelve temperatures by solving the three normal equations with Gaussian elimination, printing the amplitude, the shift, the mean level and R^2.

Python: a tangent with its asymptote, and a least-squares wave
import math


def tan_deg(x):
    """tan of x degrees, or None where it does not exist (cos x = 0)."""
    c = math.cos(math.radians(x))
    return None if abs(c) < 1e-12 else round(math.sin(math.radians(x)) / c, 2)


print([tan_deg(x) for x in (89, 89.9, 90, 90.1, 91)])   # [57.29, 572.96, None, -572.96, -57.29]


def sinusoid_fit(xs, ys, period):
    """Least squares y ~ A sin(wx) + B cos(wx) + D, w = 2 pi / period; returns a, c, d, r2 for a sin(w (x - c)) + d."""
    w = 2 * math.pi / period
    M = [[0.0] * 3 for _ in range(3)]                    # the normal equations M [A, B, D] = v
    v = [0.0] * 3
    for x, y in zip(xs, ys):
        row = [math.sin(w * x), math.cos(w * x), 1.0]
        for i in range(3):
            v[i] += row[i] * y
            for j in range(3):
                M[i][j] += row[i] * row[j]
    for col in range(3):                                 # Gaussian elimination with a pivot
        piv = max(range(col, 3), key=lambda r: abs(M[r][col]))
        M[col], M[piv] = M[piv], M[col]
        v[col], v[piv] = v[piv], v[col]
        for r in range(col + 1, 3):
            f = M[r][col] / M[col][col]
            for j in range(col, 3):
                M[r][j] -= f * M[col][j]
            v[r] -= f * v[col]
    sol = [0.0] * 3
    for i in (2, 1, 0):
        sol[i] = (v[i] - sum(M[i][j] * sol[j] for j in range(i + 1, 3))) / M[i][i]
    A, B, D = sol
    a = math.hypot(A, B)
    c = (-math.atan2(B, A) / w) % period                 # A sin + B cos = a sin(w (x - c))
    mean = sum(ys) / len(ys)
    res = sum((y - (A * math.sin(w * x) + B * math.cos(w * x) + D)) ** 2 for x, y in zip(xs, ys))
    tot = sum((y - mean) ** 2 for y in ys)
    return a, c, D, 1 - res / tot


months = list(range(1, 13))
temp = [4.1, 5.0, 8.6, 12.9, 17.5, 21.0, 23.4, 22.8, 19.1, 13.9, 8.2, 4.9]
a, c, d, r2 = sinusoid_fit(months, temp, 12)
print(round(a, 2), round(c, 2), round(d, 2), round(r2, 4))   # 9.77 4.09 13.45 0.9959
JavaScript: the same two things
const rad = (d) => (d * Math.PI) / 180

function tanDeg(x) {
  // tan of x degrees, or null where it does not exist (cos x = 0)
  const c = Math.cos(rad(x))
  return Math.abs(c) < 1e-12 ? null : +(Math.sin(rad(x)) / c).toFixed(2)
}

;[89, 89.9, 90, 90.1, 91].map(tanDeg)           // [57.29, 572.96, null, -572.96, -57.29]

function sinusoidFit(xs, ys, period) {
  // least squares y ~ A sin(wx) + B cos(wx) + D, w = 2 pi / period; returns [a, c, d, r2] for a sin(w (x - c)) + d
  const w = (2 * Math.PI) / period
  const M = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]            // the normal equations M [A, B, D] = v
  const v = [0, 0, 0]
  xs.forEach((x, k) => {
    const row = [Math.sin(w * x), Math.cos(w * x), 1]
    for (let i = 0; i < 3; i++) {
      v[i] += row[i] * ys[k]
      for (let j = 0; j < 3; j++) M[i][j] += row[i] * row[j]
    }
  })
  for (let col = 0; col < 3; col++) {                    // Gaussian elimination with a pivot
    let piv = col
    for (let r = col + 1; r < 3; r++) if (Math.abs(M[r][col]) > Math.abs(M[piv][col])) piv = r
    ;[M[col], M[piv]] = [M[piv], M[col]]
    ;[v[col], v[piv]] = [v[piv], v[col]]
    for (let r = col + 1; r < 3; r++) {
      const f = M[r][col] / M[col][col]
      for (let j = col; j < 3; j++) M[r][j] -= f * M[col][j]
      v[r] -= f * v[col]
    }
  }
  const sol = [0, 0, 0]
  for (let i = 2; i >= 0; i--) {
    let s = v[i]
    for (let j = i + 1; j < 3; j++) s -= M[i][j] * sol[j]
    sol[i] = s / M[i][i]
  }
  const [A, B, D] = sol
  const a = Math.hypot(A, B)
  const c = (((-Math.atan2(B, A) / w) % period) + period) % period   // A sin + B cos = a sin(w (x - c))
  const mean = ys.reduce((s, y) => s + y, 0) / ys.length
  let res = 0, tot = 0
  xs.forEach((x, k) => {
    res += (ys[k] - (A * Math.sin(w * x) + B * Math.cos(w * x) + D)) ** 2
    tot += (ys[k] - mean) ** 2
  })
  return [a, c, D, 1 - res / tot]
}

const months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
const temp = [4.1, 5.0, 8.6, 12.9, 17.5, 21.0, 23.4, 22.8, 19.1, 13.9, 8.2, 4.9]
const [a, c, d, r2] = sinusoidFit(months, temp, 12)
;[+a.toFixed(2), +c.toFixed(2), +d.toFixed(2), +r2.toFixed(4)]   // [9.77, 4.09, 13.45, 0.9959]
C++: the same two things with <cmath>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const double PI = 3.14159265358979323846;
double xs[12], ys[12];
double M[9], v[3], sol[3];            // the normal equations M [A, B, D] = v

double tanDeg(double x) { return sin(x * PI / 180) / cos(x * PI / 180); }

// the angle of the point (x, y), from -PI to PI, in any quadrant (what atan2 does)
double angleOf(double y, double x) {
  if (x > 0) return atan(y / x);
  if (x < 0) return atan(y / x) + (y >= 0 ? PI : -PI);
  return y >= 0 ? PI / 2 : -PI / 2;
}

int main() {
  double test[5] = {89, 89.9, 90.1, 91, 45};
  for (int i = 0; i < 4; i++) printf("%.2f ", tanDeg(test[i]));
  printf("\n");

  double temp[12] = {4.1, 5.0, 8.6, 12.9, 17.5, 21.0, 23.4, 22.8, 19.1, 13.9, 8.2, 4.9};
  double period = 12;
  double w = 2 * PI / period;
  for (int i = 0; i < 12; i++) { xs[i] = i + 1; ys[i] = temp[i]; }
  for (int i = 0; i < 9; i++) M[i] = 0;
  for (int i = 0; i < 3; i++) v[i] = 0;
  for (int k = 0; k < 12; k++) {
    double row[3];
    row[0] = sin(w * xs[k]); row[1] = cos(w * xs[k]); row[2] = 1;
    for (int i = 0; i < 3; i++) {
      v[i] += row[i] * ys[k];
      for (int j = 0; j < 3; j++) M[i * 3 + j] += row[i] * row[j];
    }
  }
  for (int col = 0; col < 3; col++) {                  // Gaussian elimination with a pivot
    int piv = col;
    for (int r = col + 1; r < 3; r++) if (fabs(M[r * 3 + col]) > fabs(M[piv * 3 + col])) piv = r;
    for (int j = 0; j < 3; j++) { double t = M[col * 3 + j]; M[col * 3 + j] = M[piv * 3 + j]; M[piv * 3 + j] = t; }
    double t2 = v[col]; v[col] = v[piv]; v[piv] = t2;
    for (int r = col + 1; r < 3; r++) {
      double f = M[r * 3 + col] / M[col * 3 + col];
      for (int j = col; j < 3; j++) M[r * 3 + j] -= f * M[col * 3 + j];
      v[r] -= f * v[col];
    }
  }
  for (int i = 2; i >= 0; i--) {
    double s = v[i];
    for (int j = i + 1; j < 3; j++) s -= M[i * 3 + j] * sol[j];
    sol[i] = s / M[i * 3 + i];
  }
  double A = sol[0], B = sol[1], D = sol[2];
  double a = sqrt(A * A + B * B);
  double c = -angleOf(B, A) / w;
  c = c - period * floor(c / period);                  // into one period
  double mean = 0;
  for (int k = 0; k < 12; k++) mean += ys[k] / 12;
  double res = 0, tot = 0;
  for (int k = 0; k < 12; k++) {
    double fit = A * sin(w * xs[k]) + B * cos(w * xs[k]) + D;
    res += (ys[k] - fit) * (ys[k] - fit);
    tot += (ys[k] - mean) * (ys[k] - mean);
  }
  printf("%.2f %.2f %.2f %.4f\n", a, c, D, 1 - res / tot);
  return 0;
}

/* output:
57.29 572.96 -572.96 -57.29
9.77 4.09 13.45 0.9959
*/

Where do the graphs of the trigonometric functions come from?

Graphs of the trigonometric functions came late: the functions began as lengths in a circle, and only when a quantity was plotted against another did the wave appear.

  • About 1350. Nicole Oresme drew a quantity that changes, such as a speed over time, as a line whose height shows its size at each moment, an early forerunner of the graph.
  • 1630s. Roberval drew the sine curve as a companion of the cycloid and found the area under one arch. It is among the first sine waves drawn as a curve.
  • 1748. Euler's Introductio treats sine and cosine as functions of a number, with angles in radians, so that \sin x can be graphed against x and differentiated.
  • 1822. Fourier's Théorie analytique de la chaleur shows that a periodic function can be written as a sum of sine and cosine waves, which is why adding waves, as in this article, describes sounds, tides and signals.
  • 1863. Helmholtz's Die Lehre von den Tonempfindungen describes a pure tone as a sine wave and a musical note as a sum of them.
  • Late 1800s. Alternating-current power systems made the sine wave of voltage a daily object, with the mains frequency fixed at 50 or 60 Hz.

What are the common mistakes with trigonometric graphs?

The most common mistakes with trigonometric graphs are the nine below, each with the correct statement.

MistakeCorrect
❌ The tangent graph is a wave between -1 and 1It has no highest or lowest point: it rises from far below to far above between asymptotes.
❌ Join the branches of \tan x through the asymptoteThe function does not exist at 90^\circ: lift the pen, and draw the dashed asymptote.
❌ The period of \tan x is 360^\circIt is 180^\circ, since half a turn changes the signs of sine and cosine together.
❌ The period of \sin bx is 360^\circ bIt is (360^\circ)/(b): a larger b squeezes the wave.
❌ y=\sin(2x-60^\circ) is shifted 60^\circ to the rightFactor out the 2: \sin\left(2(x-30^\circ)\right), so the shift is 30^\circ.
❌ The amplitude of 3\tan x is 3A tangent has no amplitude: 3 only stretches it.
❌ Draw \sec x dipping between -1 and 1\sec x=(1)/(\cos x) always has |\sec x|\ge1: its U-shapes touch 1 and -1 and no lower.
❌ \sin2x+\sin3x has period 2×3 or 360^\circ·6It repeats every (360^\circ)/(\gcd(2,3))=360^\circ; the sum of waves of different frequencies is not even a sine wave.
❌ Plot \sin x for x up to 360 with the calculator in radian mode360 radians is about 57 turns. Match the unit of the axis and the mode of the program.

Practice: test your understanding

These questions mix everything above. A wrong answer costs nothing here: read the hint and try again.

True or false?

Decide whether each statement is True or False.

  • The graph of \tan x has vertical asymptotes at 90^\circ+180^\circ n.
  • The period of \tan x is 360^\circ.
  • \sec x can equal 0.5.
  • y=\sin2x has period 180^\circ.
  • The graph of y=\sin(2x-60^\circ) is the graph of \sin2x shifted 60^\circ to the right.
  • The sum of two sine waves of different frequencies is again a sine wave.

A period

What is the period, in degrees, of y=3\sin4x-1?

The highest point

What is the largest value of y=5-2\cos3x?

Between asymptotes

How far apart, in degrees, are two neighbouring asymptotes of y=\tan3x?

The shift

By how many degrees to the right is y=\sin(2x-60^\circ) shifted from y=\sin2x?

The midline

A wave has highest value 7 and lowest value -3. At what height y=d is its midline?

A sum

What is the period, in degrees, of \sin2x+\sin3x?

Never between

Which function never takes a value between -1 and 1?

  • \csc x
  • \tan x
  • \cos x
  • \cot x

Which have asymptotes?

Which graphs have vertical asymptotes? Choose all that apply.

  • y=\tan x
  • y=\cos x
  • y=\cot x
  • y=\sec x
  • y=\sin x

Order the sketch

Put the steps of sketching y=3\sin(2x-60^\circ)+1 in order.

Fill in the reciprocal

Complete the definition of the secant.

A tide period

High tide is at 3 h and again at 15.4 h. What is the period of the tide?

  • 12.4 h
  • 6.2 h
  • 18.4 h
  • 24.8 h

Summary: trigonometric graphs at a glance

  • From the circle: sine and cosine are the height and width of the point; tangent, cotangent, secant and cosecant are the lengths cut by the ray on the lines x=1 and y=1.
  • Tangent: asymptotes at 90^\circ+180^\circ n, period 180^\circ, odd, no amplitude, through (45^\circ,1).
  • Reciprocals: asymptotes where the base is 0, tips where it is ±1, |\sec x|\ge1, |\csc x|\ge1; \cot x=-\tan(x-90^\circ).
  • Transformations: y=a f(b(x-c))+d; period (360^\circ)/(|b|) (or (180^\circ)/(|b|)), shift c, lift d; in bx-B the shift is B/b.
  • Sketching: period, start B/b, five points a quarter of a period apart, heights d, d+a, d, d-a, d; a tangent from its asymptotes and the points at ±45^\circ.
  • Reading: d=(\max+\min)/(2), a=(\max-\min)/(2), P from two peaks, cosine shifted by a peak.
  • Adding: same frequency, one wave; whole-number frequencies, period (360^\circ)/(\gcd); irrational ratio, no period; close frequencies beat.
  • Fitting: a known period makes y≈ A\sin bx+B\cos bx+D linear; R^2 measures the fit.

Glossary: key terms

Vertical asymptote
A vertical line that a graph approaches without ever touching, at an x where the function does not exist, such as x = 90 degrees for the tangent.
Period
The smallest positive length after which a graph repeats exactly: 360 degrees for the sine and 180 degrees for the tangent.
Amplitude
The distance from the midline of a sine or cosine wave to its highest point, equal to the absolute value of a in a sin(bx) plus d.
Midline
The horizontal line halfway between the highest and the lowest value of a wave, y equal to d.
Phase shift
The distance c that a graph y = a f(b(x - c)) + d is moved to the right compared with the parent; for f(bx - B) it is B divided by b.
Sinusoid
A graph of the form a sin(b(x - c)) + d; sine and cosine waves of any amplitude, period and shift are all sinusoids.
Frequency
The number of cycles per unit: the reciprocal of the period, so a period of 20 milliseconds is 50 cycles per second, 50 hertz.
Beat
The slow swelling and fading of the sum of two waves of nearby frequencies, repeating as often as the difference of the frequencies.
Least squares
A way to fit a curve to measurements by choosing the numbers that make the sum of the squared vertical distances to the points as small as possible.

Frequently asked questions

What does the graph of tan x look like?

It is a series of rising branches separated by vertical asymptotes at 90 degrees plus 180 degrees times n. Each branch passes through the x-axis, goes through the point at 45 degrees with height 1, and runs from far below to far above.

What is the period of tangent and cotangent?

Both repeat every 180 degrees, or pi radians, not 360. Half a turn changes the sign of both sine and cosine, so their quotient stays the same. For tan of b x the period is 180 degrees divided by b.

How do you graph secant and cosecant?

Draw cosine or sine lightly. Put asymptotes where it is zero, mark the points where it is 1 or minus 1, and draw U-shaped branches from those points to the asymptotes. The graph never lies between minus 1 and 1.

What is the phase shift of y = sin(2x − π/3)?

Factor out the 2: sin of 2 times x minus pi over 6. The graph is shifted pi over 6 radians, 30 degrees, to the right, not pi over 3. The shift is B divided by b.

How do you find the equation of a sine graph from its picture?

Take the midline as the average of the highest and lowest values and the amplitude as half their difference. Measure the period between two peaks, set b to 360 degrees over the period, and shift a cosine by the x of a peak.

Is the sum of two sine waves a sine wave?

Only if they have the same frequency, when the sum is one sine wave. With different frequencies the sum is not a sine wave; it repeats if the frequencies are whole numbers, and never repeats if their ratio is irrational.

How do you fit a sine wave to data?

Choose the period, then fit y as A sin plus B cos plus D by least squares, which is linear. The amplitude is the square root of A squared plus B squared, and the fit quality is R squared. Try several periods if unsure.

What is the range of secant and cosecant?

All numbers that are at least 1 or at most minus 1, with nothing in between. They are the reciprocals of cosine and sine, which never leave the interval from minus 1 to 1, so the reciprocals never enter it.

References

  1. James Stewart, Lothar Redlin, Saleem Watson (2016). Precalculus: Mathematics for Calculus (chapters on trigonometric functions of real numbers and graphs). Cengage Learning.
  2. Eli Maor (1998). Trigonometric Delights. Princeton University Press.
  3. I. M. Gelfand, Mark Saul (2001). Trigonometry (2nd ed.). Birkhäuser.
  4. Carl B. Boyer, Uta C. Merzbach (2011). A History of Mathematics (3rd ed.). Wiley.
  5. Leonhard Euler (1748). Introductio in analysin infinitorum. Marcum-Michaelem Bousquet.
  6. Joseph Fourier (1822). Théorie analytique de la chaleur. Firmin Didot.
  7. Hermann von Helmholtz (1863). Die Lehre von den Tonempfindungen. Vieweg.