56

Suppose $\displaystyle P(x,y)$ a polynomial in the variables $x,y$.

For example, $\displaystyle x^4$ or $\displaystyle x^3y^2 + 3xy + 1$.

Is there a general method which allows us to evaluate the indefinite integral

$$ \int P(\sin x, \cos x) \text{d} x$$

What about the case when $\displaystyle P(x,y)$ is a rational function (i.e. a ratio of two polynomials)?

Example of a rational function: $\displaystyle \frac{x^2y + y^3}{x+y}$.


This is being asked in an effort to cut down on duplicates, see here: Coping with *abstract* duplicate questions.

and here: List of Generalizations of Common Questions.

Aryabhata
  • 82,206

3 Answers3

53

There are several general approaches to integrals that involve expressions with sines and cosines, polynomial expressions being the simplest ones.

Weierstrass Substitution

A method that always works is Weierstrass substitution, which will turn such an integral into an integral of rational functions, which in turn can always be solved, at least in principle, by the method of partial fractions. This works even for rational functions of sine and cosine, as well as functions that involve the other trigonometric functions.

Weierstrass substitution replaces sines and cosines (and by extension, tangents, cotangents, secants, and cosecants) by rational functions of a new variable. The identities begin by the trigonometric substitution $t = \tan\frac{x}{2}$, with $-\pi\lt x\lt \pi$, which yields $$\begin{align*} \sin x &= \frac{2t}{1+t^2}\\ \cos x &= \frac{1-t^2}{1+t^2}\\ dx &= \frac{2\,dt}{1+t^2}. \end{align*}$$ For example, if we have $$\int \frac{\sin x-\cos x}{\sin x+\cos x}\,dx$$ using the substitution above we obtain: $$\begin{align*} \int\frac{\sin x-\cos x}{\sin x+\cos x}\,dx &= \int\left(\frac{\quad\frac{2t}{1+t^2} - \frac{1-t^2}{1+t^2}\quad}{\frac{2t}{1+t^2} + \frac{1-t^2}{1+t^2}}\right)\left(\frac{2}{1+t^2}\right)\,dt\\ &= \int\left(\frac{\quad\frac{2t-1+t^2}{1+t^2}\quad}{\frac{1+2t-t^2}{1+t^2}}\right) \left(\frac{2}{1+t^2}\right)\,dt\\ &= \int\left(\frac{2t-1+t^2}{2t+1-t^2}\right)\left(\frac{2}{1+t^2}\right)\,dt\\ &= 2\int\frac{2t-1+t^2}{(1+t^2)(2t+1-t^2)}\,dt \end{align*}$$ which can then be integrated by the method of partial fractions.

Substitutions and Reduction formulas

However, there are usually faster methods, particularly for polynomial expressions. By breaking up the integral into a sum of integrals corresponding to the monomials, the problem reduces to solving integrals of the form $$\int \left(\sin x\right)^n \left(\cos x\right)^m\,dx$$ with $n$ and $m$ nonnegative integers. The standard methods then are:

  1. If $n$ is odd, then "reserve" one sine, and transform the others into cosines by using the identity $\sin^2 x = 1-\cos^2x$. Then do the change of variable $u=\cos x$ to transform the integral into the integral of a polynomial. For example, $$\int \left(\sin x\right)^5\left(\cos x\right)^2\,dx,$$ then take $(\sin x)^5$, and write it as $$\sin x(\sin x)^4 = \sin x(\sin^2x)^2 = \sin x(1-\cos^2 x)^2.$$ Then setting $u=\cos x$ and $du = -\sin x\,dx$, we get $$\int\left(\sin x\right)^4\left(\cos x\right)^2\,dx = \int \sin x\left(1-\cos^2x\right)^2\left(\cos x\right)^2\,dx = -\int (1-u^2)^2u^2\,du,$$ which can be solved easily.

  2. If $m$ is odd, then do the same trick by by "reserving" one cosine and using the substitution $u=\sin x$. For example, $$\int \sin^2x\cos^3x\,dx = \int \sin^2x(\cos^2x)\cos x\,dx = \int(\sin^2x)(1-\sin^2x)\cos x\,dx$$ and then setting $u=\sin x$, $du = \cos x\,dx$, we get $$\int \sin^2x\cos^3x\,dx = \int u^2(1-u^2)\,du,$$ which can be solved easily again.

  3. If $n$ and $m$ are both even, then either replace all the sines with cosines or vice versa, using $\sin^2 x = 1 - \cos^2x$ or $\cos^2x = 1-\sin^2 x$, and expand. This will leave integrals of the form $$\int \sin^n x\,dx\qquad\text{or}\quad \int \cos^m x\,dx$$ with $n$ and $m$ even positive and even. In that situation, one can use the reduction formulas, which can be obtained by using integration by parts: $$\begin{align*} \int \sin^n x\,dx &= - \frac{1}{n}\sin^{n-1} x\cos x + \frac{n-1}{n}\int \sin^{n-2}x\,dx,\\ \int \cos^m x\,dx &= \frac{1}{m}\cos^{m-1} x\sin x + \frac{n-1}{n}\int \cos^{n-2}x\,dx. \end{align*}$$ By repeated application of these formulas, one eventually ends up with an integral of the form $\int \,dx$ which can be solved directly.

The process can be shortened if you happen to spot or know some trigonometric identities; for example, the power reduction formulas allow you to replace powers of sines or cosines by expressions of multiple angles, e.g., $$\sin^4\theta = \frac{3-4\cos(2\theta)+\cos(4\theta)}{8}$$ could replace a single integral with three integrals that can be done fairly easily via substitution.

Other methods

If you are comfortable enough integrating functions with a complex variable in it, then the method described by Qiaochu will transform any integral that involves sines and cosines in any way into an integral that involves exponential functions instead.

Arturo Magidin
  • 398,050
  • 3
    Ah, so that's what that substitution is called. – Qiaochu Yuan Mar 30 '11 at 18:56
  • @Qiaochu: You mean, Weierstrass substitution? Yes; my calculus teacher used to call it "Weierstrass magic $t$-substitution method", because it worked like magic no matter what your integral was. – Arturo Magidin Mar 30 '11 at 19:00
  • Can we merge the two answers? That would make it easier to have an 'accepted answer'. – Aryabhata Mar 30 '11 at 19:27
  • @Moron: Well, since this is a "community wiki", pretty much anyone can edit. I've just spent some time organizing mine a bit more, so other methods can be added to the list easily enough; I'm game. – Arturo Magidin Mar 30 '11 at 19:44
  • No, was just thinking aloud. This is fine too. Have accepted your answer because most people asking questions would need to apply one of the techniques here. I prefer the method described by Qiaochu though and since you mention that, I have ticked this. – Aryabhata Mar 30 '11 at 19:48
  • @Arturo Magidin, and what about when we just have $\int{\sin^n x} ,dx$ or $\int{\cos^n x} ,dx $. – HeWhoMustBeNamed Nov 04 '17 at 22:00
  • @MrReality: I'm curious... did you bother to read the answer? Because Substitution and Reduction formulas is about $n$ and $m$ non-negative. That includes the case where one is zero. Even if not, then point 3 gives you the reduction formulas which allow you to reduce those integrals until you are left with either $\int ,dx$ or with $\int\sin(x),dx$ or $\int\cos(x),dx$. So, your question was already answered in the text. – Arturo Magidin Nov 05 '17 at 23:50
  • @ArturoMagidin, Yes, I did bother to read the answer. I read that the method (the reduction formulae) given in the point #3 was used when n & m were both positive and even; so actually I meant to ask what happens if we have just one of them and the powers are odd. But I see now that if I'd read the answer more carefully I wouldn't have the doubt. – HeWhoMustBeNamed Nov 06 '17 at 14:02
36

Calculus books teach an annoying method based around using trig identities to reduce the integral to one where trig substitution can be applied. This method requires a little bit of guess-work to determine which identity should be applied, and my recollection is that it does not always work.

Here is a completely mechanical method which always works, although for simple $P$ it may require more calculation than a smarter method. Instead of using $\sin \theta, \cos \theta$, use the complex exponential $e^{i \theta}$; then Euler's formula $e^{i \theta} = \cos \theta + i \sin \theta$ tells you that $$\cos \theta = \frac{e^{i \theta} + e^{-i \theta}}{2}, \sin \theta = \frac{e^{i \theta} - e^{-i \theta}}{2i}$$

and now the problem is reduced to integrating a sum of exponentials.

Example. The integral $\int_{0}^{2\pi} \cos^{2n} \theta \, d \theta$ has come up several times on math.SE in one form or another. It is readily solved using this method: write it as

$$\frac{1}{4^n} \int_0^{2\pi} (e^{i \theta} + e^{-i \theta})^{2n} \, d \theta$$

and note that when integrating from $0$ to $2\pi$ all of the terms vanish except the constant term, so the final answer is

$$\frac{2\pi}{4^n} {2n \choose n}.$$

This method generalizes to the case when $P$ is replaced by a rational function; in that case the integrand becomes a rational function of $e^{i \theta}$ (rather than a Laurent polynomial) and using $u$-substitution we can reduce the problem to integrating a rational function, which can be done in a number of ways (partial fractions, residues...).

Qiaochu Yuan
  • 419,620
  • 3
    I guess I described the "annoying method..." – Arturo Magidin Mar 30 '11 at 18:58
  • 1
    @Arturo: to be fair, my recollection is that when my calculus books discussed this method they left out how to do the third case when $n, m > 2$. – Qiaochu Yuan Mar 30 '11 at 19:08
  • I updated the question to include rational functions. Notifying you, in case you think the answer needs editing. – Aryabhata Mar 31 '11 at 18:50
  • I feel really awful for necroing, but I can't help but wonder if there's an error. (There likely isn't and I am simply seeing things.)

    The issue I have is: $$\int_{0}^{2\pi}\cos^{2n} \theta d\theta=\frac{1}{2^n}\int_{0}^{2\pi}\left(e^{i\theta}+e^{-\theta}\right)^{2n} d\theta$$

    Using the definition of $\cos \theta$ as $\frac{e^{i\theta}+e^{-i\theta}}{2}$, shouldn't it be:

    $$\int_{0}^{2\pi}\cos^{2n} \theta d\theta=\frac{1}{2^{2n}}\int_{0}^{2\pi}\left(e^{i\theta}+e^{-\theta}\right)^{2n} d\theta$$ I think you simply forgot the $2$ in the exponent.

    – 000 Apr 19 '12 at 21:45
  • @Limitless: no, you're right. My apologies. – Qiaochu Yuan Apr 19 '12 at 21:47
  • @QiaochuYuan, oh! Well, that brightened my day. I'm glad I could contribute positively to Math SE. :) – 000 Apr 19 '12 at 21:48
5

Here are some other substitutions that you can try on a rational function of trigonometric functions. We name them Bioche substitution in France.

Let $P(\sin t,\cos t)=f(t)$ where $P(x,y)$ is rational function. Let $\omega(t)=f(t)dt$.

  • If $\omega(-t)=\omega(t)$, then $u(t)=\cos t$ might be a good substitution.
    For example : $$\int \frac{\sin^3t}{2+\cos t}dt=-\int \frac{(1-\cos^2t)(-\sin t)}{2+\cos t}dt=-\int\frac{1-u^2}{2+u}=\int\frac{u^2-1}{2+u}=\int u-2+\frac{3}{u-2}du=\int u du-2\int du+3\int \frac{1}{u-2}=\frac{u^2}{2}-2u+3\log(u-2)$$
  • If $\omega(\pi-t)=\omega(t)$, then $u(t)=\sin t$ might be a good substitution.
    For example : $$\int \frac{1}{\cos t}dt=\int \frac{\cos t}{\cos^2 t}dt=\int \frac{\cos t}{1-\sin^2 t}dt=\int \frac{1}{1-u^2}du=\int \frac{1}{2} \bigg(\frac{1}{1+u}+\frac{1}{1-u}\bigg)du=\frac{1}{2}(\log(u+1)-\log(1-u))$$
  • If $\omega(\pi+t)=\omega(t)$, then $u(t)=\tan t$ might be a good substitution.
    For example : $$\int\frac{1}{1+\cos^2 t}dt=\int \frac{1}{1+\frac{1}{\cos^2 t}}\frac{dt}{\cos^2 t}=\int \frac{1}{1+\frac{\cos^2t+\sin^2t}{\cos^2 t}}\frac{dt}{\cos^2 t}=\int \frac{1}{2+\tan^2t}\frac{dt}{\cos^2 t}=\int\frac{1}{2+u^2}du=\frac{1}{\sqrt2}\arctan\frac{u}{\sqrt2}$$
  • If two of the previous relations are verified (in this case the three relations are verified), then $u=\cos(2t)$ might be a good substitution.

If none of these work, you can use the Weierstrass substitution presented in a previous answer.

Bérénice
  • 9,367