Solution:
Key idea: Multiplying the top and bottom of the fraction by cos2x turns it into 1+cos2x1−cos2x, and this simplifies to tan2x. Then we use tan2x=sec2x−1 and integrate by parts, ∫uvdx=u∫vdx−∫(dxdu∫vdx)dx.
Step 1 — Simplify the fraction.
We multiply top and bottom by cos2x, then use 1−cos2x=2sin2x and 1+cos2x=2cos2x.
sec2x+1sec2x−1=1+cos2x1−cos2x
sec2x+1sec2x−1=2cos2x2sin2x
sec2x+1sec2x−1=tan2x
Step 2 — Split.
We replace tan2x by sec2x−1.
I=∫xtan2xdx
I=∫xsec2xdx−∫xdx
Step 3 — Integrate xsec2x by parts.
We take u=x and v=sec2x, with ∫sec2xdx=tanx and ∫tanxdx=log∣secx∣.
∫xsec2xdx=xtanx−∫tanxdx
∫xsec2xdx=xtanx−log∣secx∣
Step 4 — Combine.
We subtract ∫xdx=2x2 and add the constant.
I=xtanx−log∣secx∣−2x2+C
Therefore, ∫x(sec2x+1sec2x−1)dx=xtanx−log∣secx∣−2x2+C, wherever cosx=0 and cos2x=0.