# How to integrate $\int_{-\pi}^\pi|\cos(x)|dx$

I need to calculate the average value $\mu$ with the formula: $$\mu = \frac{1}{b-a} \int_a^bf(x)\,dx$$ in my case: $$\mu = \dfrac{1}{2\pi}\int_{-\pi}^\pi |\cos(x)|\,dx =\dfrac{1}{\pi}\int_{0}^\pi |\cos(x)|\,dx$$ but the problem is that I don't know how to integrate the absolute value of $\cos$: '$|\cos(x)|$' How do I integrate it?

• $\cos x \geqslant 0$ for $0 \leqslant x \leqslant \pi/2$, and $\cos x \leqslant 0$ for $\pi/2 \leqslant x \leqslant \pi$. – Daniel Fischer Jan 21 '14 at 15:25
• Where is cos(x) negative? Where is cos(x) positive? On what interval? – Eleven-Eleven Jan 21 '14 at 15:27

## 5 Answers

Something to consider is that between $0$ and $\pi/2$, $cos$ is positive, and so $|cos| = cos$. And then between $\pi/2$ and $\pi$, $cos$ is negative, so $|cos| = -cos$.

All you need to do at that point is split your integral up:

$$\int_0^\pi |\cos(x)| \,dx = \int_0^{\pi/2} |\cos(x)|\, dx + \int_{\pi/2}^\pi |\cos(x)| \,dx = \int_0^{\pi/2} \cos(x) \,dx - \int_{\pi/2}^\pi \cos(x)\, dx.$$

You can go a step further to solving then by noting that $\int_{\pi/2}^\pi \cos(x)\, dx = -\int_0^{\pi/2} \cos(x)\, dx$, so all in all your integral resolves down to:

$$\int_0^\pi |cos(x)| \,dx = 2\int_0^{\pi/2} cos(x) \,dx.$$

But that last bit is extra to your original question :) Long story short, in the general case, when looking at integrals of absolute values you need to break it into the separate cases:

$$\int_x |f(x)| = \int_{x: f(x) \geq 0} f(x) - \int_{x: f(x) < 0} f(x)$$

Hope that helps you!

• Thank you, it really helped me :) – Mark Jan 21 '14 at 17:21

Just integrate the positive and negative parts: $$\int_0^\pi |\cos(x)|dx = \int_0^{\pi/2} |\cos(x)|dx + \int_{\pi/2}^\pi|\cos(x)|dx.$$ Knowing that $\cos(x)\geq 0$ for $x\in[0,\pi/2]$ and $\cos(x)\leq 0$ for $x\in[\pi/2, \pi]$, you have $$\int_0^{\pi/2} |\cos(x)|dx + \int_{\pi/2}^\pi|\cos(x)|dx = \int_0^{\pi/2} \cos(x)dx - \int_{\pi/2}^\pi\cos(x)dx$$ which is elementary.

$$\frac{1}{\pi}\int_0^\pi |\cos(x)|dx=\frac{1}{\pi}\int_0^{\pi/2} \cos(x)dx + \frac{1}{\pi}\int_{\pi/2}^{\pi} -\cos(x)dx=\frac{1}{\pi}[\sin(\pi/2)-\sin(0)-\sin(\pi)+\sin(\pi/2)]=\frac{1}{\pi}(1-0-0+1)=\frac{2}{\pi}$$


Hint: $\mu = \frac{2}{\pi} \int_{0}^{\frac{\pi}{2}}\cos(x) dx.$

• Sorry, but I don't really see this as a hint. I does not direct the reader towards the right question. The equation is correct, of course, but you only know it is if you already computed the thing. – 5xum Jan 21 '14 at 15:32
• Can't we conclude from the graph of $f(x)= |\cos (x)|$ ? – Inquisitive Jan 21 '14 at 15:36
• Indeed we can. But to make the answer really helpful, you should give a hint how one can read that off the graph. – Daniel Fischer Jan 21 '14 at 17:06
• I never like anyone who solves mathematic problems by "concluding" from the graph. A graph can be a good visualization of something you already know or it can give you ideas that you can then prove. If you just "see" something, but can't prove it, you can't consider it truth. Proofs "from graphs" are, in my mind, not a proof at all. – 5xum Jan 21 '14 at 20:07