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.
How to integrate tan x with u-substitution
is not one of the basic antiderivatives you memorize, so the first move is to rewrite it in terms of sine and cosine.
Now the numerator is the derivative of the denominator up to a sign, which is the signal for u-substitution (Topic 6.9). Let .
Substituting turns the whole integral into the one antiderivative you already know, , with a minus sign out front.
Integrate, then substitute back in.
Keep the absolute value
is negative on half of every period, and the logarithm of a negative number is undefined. Writing instead of silently restricts the answer to intervals where , such as .
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 on the inside.
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 gives the derivative of the inside over the inside.
A worked definite integral
Once you have the antiderivative, definite integrals follow from the Fundamental Theorem of Calculus (Topic 6.7). Evaluate .
At the upper limit , and at the lower limit , so the second term vanishes.
Check the interval first
has vertical asymptotes at . An interval such as contains one, so 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 integral in disguise.
- Topic 6.9, Integrating Using Substitution: the derivation itself, with
- Topic 6.14, Selecting Techniques for Antidifferentiation: recognizing as a pattern rather than a memorized form
- Topic 6.7, the Fundamental Theorem of Calculus and Definite Integrals: evaluating on an interval free of asymptotes
- Unit 7, separable differential equations: appears after you separate variables and integrate both sides
The companion result comes from the same substitution run on the reciprocal pairing, with and no minus sign to carry.
Common mistakes with the integral of tan x
- Dropping the absolute value and writing . That answer is only valid where , and graders read the bars.
- Losing the minus sign. Since , the numerator contributes , and forgetting it flips the sign of the whole answer.
- Answering . That is , 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 on an indefinite integral, which costs a point on free response.
The pattern behind the answer
Any integrand of the form integrates to . fits it once you notice that is the negative of the derivative of . 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?
, equivalently . Both forms are accepted on the AP exam.
Why does the integral of tan x need an absolute value?
Because the substitution ends at , whose antiderivative is for every , not just positive . Here , which is negative on half of every period, so would be undefined on those intervals while is valid between consecutive asymptotes.
Is -ln|cos x| the same as ln|sec x|?
Yes. Moving the minus sign inside makes it . The two answers differ only in appearance, not in value.
What is the integral of cot x?
. Rewrite and substitute , so and no minus sign appears.
Can I evaluate the definite integral of tan x from 0 to pi?
No. has a vertical asymptote at , which lies inside , so the integral is improper and diverges. Mechanically substituting the limits into produces a number, but that number means nothing. Always check for asymptotes inside the interval first.