Writing $|\cos x|$ as a piecewise function. I would appreciate for your guidance to the following exercise :
There is the function:
$f(x) =|\cos x|, x \in[-\pi, \pi)$ 
My question is if this function Could be also expressed with the following formula?
$$
f(x)=\begin{cases}
-\cos x, - \pi\leq x < -\pi/2\\
\cos x,\ \ \  - \pi/2\leq x<\pi
\end{cases}
$$
Is my way of thinking right?
Thank you very much in advance. 
 A: $\cos x$ is positive over the intervals 
$$\left((4k-1)\frac{\pi}{2},(4k+1)\frac{\pi}{2}\right), k\in\mathbb{Z}$$
In your case, $\left(-\frac{\pi}{2},\frac{\pi}{2}\right)$ is included in your domain, so you should actually distinguish three cases:
$$f(x)=\begin{cases}
-\cos x & - \pi\leq x < -\frac{\pi}{2}\\
\cos x & - \frac{\pi}{2}\leq x\leq \frac{\pi}{2}\\
-\cos x & \frac{\pi}{2}< x<\pi\\
\end{cases}$$
A: You have to wonder, when is $\cos(x) \ge 0$ on the domain? This is from $-\frac{\pi}{2}$ to $\frac{\pi}{2}$ so then the absolute value has no effect; on the rest of the domain the $\cos(x)<0$ so that $|\cos(x)|=-\cos(x)$ for those $x$.
So $$f(x)=\begin{cases} -\cos(x) & -\pi \le x \le -\frac{\pi}{2}\\
                        \cos(x) & -\frac{\pi}{2} \le x \le \frac{\pi}{2}\\
                        -\cos(x) & \frac{\pi}{2} \le x < \pi\\
           \end{cases}$$
A: Just to support the other answers I made a drawing:

Notice that $\cos(x)\geq 0$ when the point in the circle is on the first or the fourth quadrant, and $\cos(x) \leq 0$ when it is in the second or third quadrant. Therefore you have the answer the other guys gave.
