Why are the areas non-positive? I learnt that the integral of a function $f(\cdot)$ is the measure of an area, i.e. $\int\limits_{a}^{b}f(x)\,\mathrm{d}x$ is the area of the intersection of $x=a$, $x=b$, and $y=f(x)$.
How come some areas are non-positive.
Example: $\int\limits_{0}^{\pi}\cos x\,\mathrm{d}x=0\leq 0$.

What you can do to compute the area between the curve and the $x$ axis (y = 0) is split the integral. At $\pi/2$, the graph of $\cos x$ intersects the $x$ axis (the line $y = 0$). For values $0 \lt x \lt \pi/2$, $\cos x$ is above the $x$ axis.  For values $\pi/2 \lt x \lt \pi$, $\cos x$ is below the line $y = 0$.
To compute the area bound by the line $y = 0$ and $\cos x$, we split the integral into two integrals, subtracting the lower curve from the upper curve.
$$\begin{align} \int_0^{\pi/2} (\cos x - 0)\,dx + \int_{\pi/2}^\pi (0 - \cos x)\,dx & = \int_0^{\pi/2} \cos x \,dx - \int_{\pi/2}^\pi \cos x \,dx \\ \\ &= 2 \int_0^{\pi/2} \cos x\,dx\end{align}$$
