Worked example · Derivatives

The derivative of tan x

The slope of tan x is sec² x, which is never less than 1 and grows without bound near the asymptotes. Drag the secant to see both.

5 min read · 3 interactive figures

Drag Q toward P on y = tan x. At x = 0 the slope settles on 1, its smallest value; drag P toward either asymptote and it grows without bound.

The derivative of tan x is sec² x, which can also be written 1 + tan² x or 1/cos² x. It is defined wherever tan x is, that is, everywhere except the odd multiples of π/2.

ddx tan x = sec² x = 1cos² x = 1 + tan² x(1)
Question 1 Predict, then check with the calculator below and the graph further down.#
Figure 1 Type a function and a point; the default is tan x at 1.5, 0.07 from the asymptote. The tangent line is nearly vertical and the reported slope is 199.85. Try x = 1.57 (slope about 1.6 million), then 1.58, just past π/2 on the next branch, where the slope is about 11,800 and positive again.#

All three forms are the same function, and each is useful: sec² x is what derivative tables print[1], 1/cos² x shows where the derivative blows up, and 1 + tan² x shows at a glance that it is never less than 1. This page proves the rule, reads it off the graph, works the chain-rule cases and then uses tan x to show something most calculators get wrong. The secant-and-tangent picture behind every derivative is explained in the chapter on the derivative.

Proof by the quotient rule

Write tan x = sin x / cos x and use the quotient rule with (sin x)′ = cos x and (cos x)′ = −sin x:

ddx sin xcos x = cos x · cos x − sin x · (−sin x)cos² x = cos² x + sin² xcos² x = 1cos² x(2)

The Pythagorean identity cos² x + sin² x = 1 does all the work in the last step. Dividing that same identity by cos² x gives 1 + tan² x = sec² x, the third form in equation (1). There is also a proof straight from the limit definition, using the addition formula for tan(x + h) and the limit sin h/h → 1, but it arrives at the same place with more algebra.

Figure 2 The graph of tan x between its asymptotes at ±π/2. Drag P along the curve and Q toward it, or press the button to shrink h and sweep. The lower panel traces the slopes: a U-shaped curve with its minimum, 1, at x = 0, rising steeply at both edges. That curve is sec² x.#

Reading sec² x off the graph

Three features of the tangent graph each match a feature of sec² x. The curve rises everywhere, so its derivative is positive everywhere. The curve is steepest near the asymptotes, where it shoots off to ±∞, and cos x → 0 there, so 1/cos² x grows without bound. The curve has an inflection point at 0, where it is flattest, and sec² 0 = 1 is the minimum. Because tan x repeats every π, so does its derivative: the slope at x + π equals the slope at x.

The chain-rule cases

functionderivativecheck at a point
tan(3x)3 sec²(3x)at 0.2: 3/cos² 0.6 ≈ 4.4041
tan² x2 tan x sec² xat π/4: 2 · 1 · 2 = 4
tan(x²)2x sec²(x²)at 0: 0
x tan xtan x + x sec² xat 0: 0
ln|cos x|−tan xthe reason ∫ tan x dx = −ln|cos x| + C

The most common slip is in tan² x, which means (tan x)²: the outer function is squaring, so the chain rule gives 2 tan x times the inner derivative sec² x. Writing sec⁴ x or 2 sec x confuses the two layers. The chapter on the chain rule has a figure that makes the two layers visible as two stretches.

Near the poles, where calculators go wrong

At x = 1.5 the exact slope is 1/cos² 1.5 ≈ 199.85. The point is only 0.07 from the asymptote at π/2 ≈ 1.5708. Now try the textbook numerical recipe, the symmetric difference quotient with a step of 0.1:

tan 1.6 − tan 1.40.2 ≈ −34.23 − 5.800.2 ≈ −200.15(3)

The answer has the right size and the wrong sign. The point 1.6 lies on the other side of the asymptote, on the next branch of the curve, so the "secant" joins two different pieces of the graph. A smaller step fixes this particular case, but no fixed step is safe: move the point closer to π/2 and any given step eventually straddles the pole. This is a real failure of real software. An earlier version of the calculator on this site, which started from a step proportional to the size of x, reported about −256 ± 199 here, an error bar that did not even contain the true value.

The calculator at the top of this page avoids the trap by not relying on a secant at all: it applies the rule (tan u)′ = sec² u · u′ to the formula and evaluates it at the point, with a bound on the rounding error. Its numerical check extrapolates the difference quotients to zero step (Ridders' method[2]) from the left, from the right and symmetrically, shrinking the starting step when they disagree. At 1.5 it returns 199.8500445265, with an error bound far below the last digit shown. The rounding error that limits how small the step may go is the subject of the numerical section of the chapter on the derivative[3].

The other trigonometric derivatives follow the same pattern: (cot x)′ = −csc² x, (sec x)′ = sec x tan x and (csc x)′ = −csc x cot x, each by the quotient rule[1]. Their inverses, arcsin, arccos and arctan, are on the Derivatives of the inverse trig functions page.