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?
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) &lt; 0} f(x)
$$

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