AP Calculus AB and BC

Integral of tan x: Answer, Derivation, and Mistakes

The integral of tan x is -ln|cos x| + C, which is also written ln|sec x| + C. Rewrite tan x as sin x over cos x, then substitute u = cos x, so du = -sin x dx and the integral becomes -du/u. Keep the absolute value: cos x is negative on part of every period, so ln(cos x) alone is undefined there.

tanxdx=lncosx+C\int \tan x\,dx = -\ln\left|\cos x\right| + C

How to integrate tan x with u-substitution

tanx\tan x is not one of the basic antiderivatives you memorize, so the first move is to rewrite it in terms of sine and cosine.

tanxdx=sinxcosxdx\int \tan x\,dx = \int \frac{\sin x}{\cos x}\,dx

Now the numerator is the derivative of the denominator up to a sign, which is the signal for u-substitution (Topic 6.9). Let u=cosxu = \cos x.

u=cosx,du=sinxdx,sinxdx=duu = \cos x, \qquad du = -\sin x\,dx, \qquad \sin x\,dx = -du

Substituting turns the whole integral into the one antiderivative you already know, duu\int \frac{du}{u}, with a minus sign out front.

sinxcosxdx=duu=duu\int \frac{\sin x}{\cos x}\,dx = \int \frac{-du}{u} = -\int \frac{du}{u}

Integrate, then substitute u=cosxu = \cos x back in.

duu=lnu+C=lncosx+C-\int \frac{du}{u} = -\ln\left|u\right| + C = -\ln\left|\cos x\right| + C

Keep the absolute value

cosx\cos x is negative on half of every period, and the logarithm of a negative number is undefined. Writing ln(cosx)-\ln(\cos x) instead of lncosx-\ln\left|\cos x\right| silently restricts the answer to intervals where cosx>0\cos x > 0, such as π2<x<π2-\frac{\pi}{2} < x < \frac{\pi}{2}.

Why -ln|cos x| and ln|sec x| are the same answer

Textbooks and scoring guidelines print both forms. They are identical, because a leading minus sign on a logarithm is an exponent of 1-1 on the inside.

lncosx=lncosx1=ln1cosx=lnsecx-\ln\left|\cos x\right| = \ln\left|\cos x\right|^{-1} = \ln\left|\frac{1}{\cos x}\right| = \ln\left|\sec x\right|

Use whichever form you find easier to differentiate back. Both are correct on the AP exam, and neither is preferred, so do not waste time converting between them.

To check the answer, differentiate it. The chain rule on lncosx\ln\left|\cos x\right| gives the derivative of the inside over the inside.

ddx[lncosx]=1cosx(sinx)=sinxcosx=tanx\frac{d}{dx}\left[-\ln\left|\cos x\right|\right] = -\frac{1}{\cos x} \cdot (-\sin x) = \frac{\sin x}{\cos x} = \tan x

A worked definite integral

Once you have the antiderivative, definite integrals follow from the Fundamental Theorem of Calculus (Topic 6.7). Evaluate 0π/3tanxdx\int_0^{\pi/3} \tan x\,dx.

0π/3tanxdx=[lncosx]0π/3\int_0^{\pi/3} \tan x\,dx = \left[-\ln\left|\cos x\right|\right]_0^{\pi/3}

At the upper limit cosπ3=12\cos\frac{\pi}{3} = \frac{1}{2}, and at the lower limit cos0=1\cos 0 = 1, so the second term vanishes.

lncosπ3+lncos0=ln12+ln1=ln2-\ln\left|\cos\frac{\pi}{3}\right| + \ln\left|\cos 0\right| = -\ln\frac{1}{2} + \ln 1 = \ln 2

Check the interval first

tanx\tan x has vertical asymptotes at x=π2+kπx = \frac{\pi}{2} + k\pi. An interval such as [0,π][0, \pi] contains one, so 0πtanxdx\int_0^{\pi} \tan x\,dx is improper and the plug-in-the-limits computation is meaningless. Confirm the interval avoids every asymptote before you evaluate.

Where the integral of tan x shows up on the AP exam

This integral belongs to Unit 6, Integration and Accumulation of Change, which carries a weighting of 15 to 20 percent on both AB and BC. It is a standard example for Topic 6.9, Integrating Using Substitution, and it reappears in Topic 6.14, Selecting Techniques for Antidifferentiation, as the case where an integrand that looks like a trig function is really a 1u\frac{1}{u} integral in disguise.

  • Topic 6.9, Integrating Using Substitution: the derivation itself, with u=cosxu = \cos x
  • Topic 6.14, Selecting Techniques for Antidifferentiation: recognizing tanx\tan x as a uu\frac{u'}{u} pattern rather than a memorized form
  • Topic 6.7, the Fundamental Theorem of Calculus and Definite Integrals: evaluating abtanxdx\int_a^b \tan x\,dx on an interval free of asymptotes
  • Unit 7, separable differential equations: tanxdx\int \tan x\,dx appears after you separate variables and integrate both sides

The companion result comes from the same substitution run on the reciprocal pairing, with u=sinxu = \sin x and no minus sign to carry.

cotxdx=lnsinx+C\int \cot x\,dx = \ln\left|\sin x\right| + C

Common mistakes with the integral of tan x

  • Dropping the absolute value and writing ln(cosx)+C-\ln(\cos x) + C. That answer is only valid where cosx>0\cos x > 0, and graders read the bars.
  • Losing the minus sign. Since du=sinxdxdu = -\sin x\,dx, the numerator contributes du-du, and forgetting it flips the sign of the whole answer.
  • Answering sec2x\sec^2 x. That is ddx[tanx]\frac{d}{dx}[\tan x], the derivative, not the antiderivative.
  • Reaching for integration by parts. There is no product to split here, and the substitution finishes in one line.
  • Omitting +C+ C on an indefinite integral, which costs a point on free response.

The pattern behind the answer

Any integrand of the form uu\frac{u'}{u} integrates to lnu+C\ln|u| + C. tanx=sinxcosx\tan x = \frac{\sin x}{\cos x} fits it once you notice that sinx\sin x is the negative of the derivative of cosx\cos x. Training yourself to spot that pattern is worth more than memorizing this single result.

Every answer on this page is machine checked

An automated test differentiates the antiderivative above and confirms it returns the integrand. A wrong sign or a missing factor fails the build, so it cannot reach you.

Frequently asked questions

What is the integral of tan x?

tanxdx=lncosx+C\int \tan x\,dx = -\ln\left|\cos x\right| + C, equivalently lnsecx+C\ln\left|\sec x\right| + C. Both forms are accepted on the AP exam.

Why does the integral of tan x need an absolute value?

Because the substitution ends at duu\int \frac{du}{u}, whose antiderivative is lnu+C\ln|u| + C for every u0u \neq 0, not just positive uu. Here u=cosxu = \cos x, which is negative on half of every period, so ln(cosx)-\ln(\cos x) would be undefined on those intervals while lncosx-\ln\left|\cos x\right| is valid between consecutive asymptotes.

Is -ln|cos x| the same as ln|sec x|?

Yes. Moving the minus sign inside makes it lncosx1=ln1cosx=lnsecx\ln\left|\cos x\right|^{-1} = \ln\left|\frac{1}{\cos x}\right| = \ln\left|\sec x\right|. The two answers differ only in appearance, not in value.

What is the integral of cot x?

cotxdx=lnsinx+C\int \cot x\,dx = \ln\left|\sin x\right| + C. Rewrite cotx=cosxsinx\cot x = \frac{\cos x}{\sin x} and substitute u=sinxu = \sin x, so du=cosxdxdu = \cos x\,dx and no minus sign appears.

Can I evaluate the definite integral of tan x from 0 to pi?

No. tanx\tan x has a vertical asymptote at x=π2x = \frac{\pi}{2}, which lies inside [0,π][0, \pi], so the integral is improper and diverges. Mechanically substituting the limits into lncosx-\ln\left|\cos x\right| produces a number, but that number means nothing. Always check for asymptotes inside the interval first.