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

4.2k Views Asked by At

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?

5

There are 5 best solutions below

1
On BEST ANSWER

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!

0
On

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.

4
On

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

0
On

$$\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}$$

0
On

$\newcommand{\+}{^{\dagger}}% \newcommand{\angles}[1]{\left\langle #1 \right\rangle}% \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}% \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}% \newcommand{\ceil}[1]{\,\left\lceil #1 \right\rceil\,}% \newcommand{\dd}{{\rm d}}% \newcommand{\down}{\downarrow}% \newcommand{\ds}[1]{\displaystyle{#1}}% \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}% \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}% \newcommand{\fermi}{\,{\rm f}}% \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}% \newcommand{\half}{{1 \over 2}}% \newcommand{\ic}{{\rm i}}% \newcommand{\iff}{\Longleftrightarrow} \newcommand{\imp}{\Longrightarrow}% \newcommand{\isdiv}{\,\left.\right\vert\,}% \newcommand{\ket}[1]{\left\vert #1\right\rangle}% \newcommand{\ol}[1]{\overline{#1}}% \newcommand{\pars}[1]{\left( #1 \right)}% \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\pp}{{\cal P}}% \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}% \newcommand{\sech}{\,{\rm sech}}% \newcommand{\sgn}{\,{\rm sgn}}% \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}} \newcommand{\ul}[1]{\underline{#1}}% \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}$ $$\color{#00f}{\large% \int_{-\pi}^{\pi}\verts{\cos\pars{x}}\,\dd x} =2\int_{0}^{\pi}\verts{\cos\pars{x}}\,\dd x =2\int_{-\pi/2}^{\pi/2}\verts{\sin\pars{x}}\,\dd x =4\int_{0}^{\pi/2}\sin\pars{x}\,\dd x = \color{#00f}{\large 4} $$