# How to calculate this integral $\int_{-\pi}^\pi \cos(rx) \cos(kx)dx$ [duplicate]

How should I calculate this integral? $$\int_{-\pi}^\pi \cos(rx) \cos(kx)dx$$

[My attempt] $$\int_{-\pi}^\pi \cos(rx) \cos(kx)dx=2\int_0^\pi \frac{1}{2}\cos(r+k)x +\cos(r-k)xdx \\=[\frac{1}{r+k}\sin(r+k)x+\frac{1}{r-k}sin(r-k)x]_0^\pi \\ =\frac{1}{r+k}\sin(r+k)\pi+\frac{1}{r-k}\sin(r-k)\pi$$ I have calculated so far, but I do not know the steps ahead. What should I do?

## marked as duplicate by Martin R, YuiTo Cheng, cmk, Adrian Keister, ThorWittichJul 12 at 17:22

• How did your attempt come to life? Did you evaluate the primitive function? did you prove that differentiating? – DonAntonio Jul 12 at 9:44
• mathworld.wolfram.com/WernerFormulas.html – lab bhattacharjee Jul 12 at 9:44
• You calculated the integral, so what is your question? – Martin R Jul 12 at 9:59
• @MartinR Does this problem not calculate from there? I asked because I did not think this was the end. – hichewness Jul 12 at 9:59
• Use parenthesis in the integrand of your attempt when multiplying by $\frac{1}{2}$ – Hussain-Alqatari Jul 12 at 10:09

Hint: Use that $$\cos(x)\cos(y)=\frac{1}{2}\left(\cos(x-y)+\cos(x+y)\right)$$ Your result should be $$2\,{\frac {k\sin \left( \pi\,k \right) \cos \left( \pi\,r \right) -r \cos \left( \pi\,k \right) \sin \left( \pi\,r \right) }{{k}^{2}-{r}^{2 }}}$$

• THanks I added my attempt. – hichewness Jul 12 at 9:59
• Apparently OP already used that identity. – Martin R Jul 12 at 9:59

$$\cos (rx)\cos (kx)=\frac {\cos((r+k)x) +\cos((r-k)x)} 2$$. Can you now compute the integral?

• I added my attempt. but does this problem not calculate from there? I asked because I did not think this was the end. – hichewness Jul 12 at 9:59
• Assuming that $r$ and $k$ are integers what you have obtained is $0$ if $r \neq k$ (because $\sin (n\pi)=0$ for all integers $n$). However you are dividing by $r-k$ so your calculation is not valid when $r=k$. You have to handle this case separately. – Kavi Rama Murthy Jul 12 at 10:09

Note that $$\cos(u)\cos(v)=\frac{1}{2}[\cos(u+v)+\cos(u-v)]$$

Therefore, $$\int_{a}^{b}\cos(u)\cos(v)dx=\frac{1}{2}\int_{a}^{b}[\cos(u+v)+\cos(u-v)]dx$$

Putting $$a=-\pi$$, $$b=\pi$$, $$u=rx$$, $$v=kx$$, we get

$$\int_{-\pi}^{\pi}\cos(rx)\cos(kx)dx=\frac{1}{2}\int_{-\pi}^{\pi}[\cos(rx+kx)+\cos(rx-kx)]dx$$

$$=\frac{1}{2}\int_{-\pi}^{\pi}[\cos((r+k)x)+\cos((r-k))]dx$$

$$=\frac{1}{2}[\frac{\sin((r+k)x)}{r+k}+\frac{\sin((r-k)x)}{r-k}]_{-\pi}^{\pi}$$

$$=\frac{1}{2}[\frac{\sin((r+k)\pi)}{r+k}+\frac{\sin((r-k)\pi)}{r-k}]-\frac{1}{2}[\frac{-\sin((r+k)\pi)}{r+k}+\frac{-\sin((r-k)\pi)}{r-k}]$$

$$=\frac{1}{2}[\frac{\sin((r+k)\pi)}{r+k}+\frac{\sin((r-k)\pi)}{r-k}]+\frac{1}{2}[\frac{\sin((r+k)\pi)}{r+k}+\frac{\sin((r-k)\pi)}{r-k}]$$

$$=\frac{\sin((r+k)\pi)}{r+k}+\frac{\sin((r-k)\pi)}{r-k}$$