With a view to expressing the primitive in the form: :$\displaystyle \int u \frac {\mathrm d v}{\mathrm d x} \ \mathrm d x = u v - \int v \frac {\mathrm d u}{\mathrm d x} \ \mathrm d x$ let: {{begin-eqn}} {{eqn | l = u       | r = \frac x {\cos^{n - 2} a x}       | c =  }} {{eqn | r = x \cos^{- n + 2} a x       | c =  }} {{eqn | ll= \implies       | l = \frac {\mathrm d u} {\mathrm d x}       | r = x \frac {\mathrm d} {\mathrm d x} \left({\cos^{- n + 2} a x}\right) + \left({\frac {\mathrm d} {\mathrm d x} x}\right) \left({\cos^{- n + 2} a x}\right)       | c = Product Rule }} {{eqn | r = -a x \left({- n + 2}\right) \cos^{- n + 1} a x \sin a x + \cos^{- n + 2} a x       | c = Derivative of $\cos a x$, Derivative of Power, Chain Rule for Derivatives }} {{eqn | r = \frac {a x \left({n - 2}\right) \sin a x} {\cos^{n - 1} a x} + \cos^{- n + 2} a x       | c = simplifying }} {{end-eqn}} and let: {{begin-eqn}} {{eqn | l = \frac {\mathrm d v} {\mathrm d x}       | r = \frac 1 {\cos^2 a x}       | c =  }} {{eqn | r = \sec^2 a x       | c = Secant is $\dfrac 1 \cos$ }} {{eqn | ll= \implies       | l = v       | r = \frac {\tan a x} a       | c = Primitive of $\sec^2 a x$ }} {{end-eqn}} Then: {{begin-eqn}} {{eqn | l = \int \frac {x \ \mathrm d x} {\cos^n a x}       | r = \left({\frac x {\cos^{n - 2} a x} }\right) \left({\frac {\tan a x} a}\right)       | c = Integration by Parts }} {{eqn | o =        | ro= -       | r = \int \left({\frac {\tan a x} a}\right) \left({\frac {a x \left({n - 2}\right) \sin a x} {\cos^{n - 1} a x} + \cos^{- n + 2} a x }\right) \ \mathrm d x       | c =  }} {{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x} - \int \left({\frac {x \left({n - 2}\right) \sin^2 a x} {\cos^n a x} -\frac {\sin a x}{a \cos^{n - 1} a x} }\right) \ \mathrm d x       | c = simplifying }} {{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x} - \left({n - 2}\right) \int \frac {x \sin^2 a x} {\cos^n a x} \ \mathrm d x + \frac 1 a \int \frac {\sin a x}{\cos^{n - 1} a x} \ \mathrm d x       | c = Linear Combination of Integrals }} {{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x}       | c =  }} {{eqn | o =        | ro= -       | r = \left({n - 2}\right) \int \frac {x \left({1 - \cos^2 a x}\right)} {\cos^n a x} \ \mathrm d x       | c = Sum of Squares of Sine and Cosine }} {{eqn | o =        | ro= +       | r = \frac 1 a \left({\frac {-1} {\left({n - 2}\right) \cos^{n - 2} a x} }\right)       | c = Primitive of $\cos^n a x \sin a x$ }} {{eqn | r = \frac {x \sin a x} {a \cos^{n - 1} a x}       | c =  }} {{eqn | o =        | ro= -       | r = \left({n - 2}\right) \int \frac {x \ \mathrm d x} {\cos^n a x} + \left({n - 2}\right) \int \frac {x \ \mathrm d x} {\cos^{n - 2} a x}       | c = Linear Combination of Integrals and simplifying }} {{eqn | o =        | ro= +       | r = \frac 1 a \left({\frac {-1} {\left({n - 2}\right) a \cos^{n - 2} a x} }\right)       | c =  }} {{end-eqn}} This leads to: {{begin-eqn}} {{eqn | l = \left({n - 1}\right) \int \frac {x \ \mathrm d x} {\cos^n a x}       | r = \frac {x \sin a x} {a \cos^{n - 1} a x} + \left({n - 2}\right) \int \frac {x \ \mathrm d x} {\cos^{n - 2} a x} - \frac 1 {a^2 \left({n - 2}\right) \cos^{n - 2} a x}       | c =  }} {{eqn | ll= \implies       | l = \int \frac {x \ \mathrm d x} {\cos^n a x}       | r = \frac {x \sin a x} {a \left({n - 1}\right) \cos^{n - 1} a x} - \frac 1 {a^2 \left({n - 1}\right) \left({n - 2}\right) \cos^{n - 2} a x} + \frac {n - 2} {n - 1} \int \frac {\mathrm d x} {\cos^{n - 2} a x} + C       | c =  }} {{end-eqn}} {{qed}}