Calculating the area bounded by $y=x-2$ and the $x$-axis on the interval $[-1,3]$. Integration gives a value that conflicts with geometry. I am trying to calculate the area bounded by the equation $y=x-2$ along the x-axis between the interval $[-1, 3 ]$.

Evaluating the following integral give me the result of $-4$
$$\int_{-1}^{3}(x-2) \mathbf{d}x$$
But, when I calculate area, using triangle's formula 1/2*b*h, the result comes out to be 5.
Area of bigger triangle = 1/2 * 3 * 3 = 9/2
Area of smaller triangle = 1/2 * 1 * 1 = 1/2
Total area =  9/2 + 1/2 = 5
Since the area is always positive, I am not taking account of + or - signs. If I take that into account the answer comes out to be correct (same as integration).
What am I doing wrong? And why do I need to account for sign changes?
 A: There is a concept of area, which is always positive, and a concept of algebraic or oriented area, which can take both signs.
With an integral like $\displaystyle\int f(x)\,dx$, which can be negative when $f$ is negative, you obtain an algebraic area. If you want to compute it geometrically, you need to identify the positively oriented and negatively oriented zones and take the difference of their areas.
If you don't want to deal with algebraic areas, compute the integral $\displaystyle\int |f(x)|\,dx$ instead.
A: The problem in your solution is that if $f$ is negative on interval $[a,b]$, $\int _a ^b f(x)dx = -\int _a ^b \lvert f(x) \rvert dx$. If you are trying to calculate the total area disregarding whether they are above or below the x-axis, always integrate the absolute value of the function, as "normal" integration would give the result of the area above the x-axis minus the area below the x-axis.
The reason why would have to do with the definition of integral. If $f$ is negative over a certain interval, no matter how you partition that interval, all of its Riemann sum is going to be less or equal to zero. Furthermore, as the Riemann sum comes to a limit, it would be the negation of the area under the x-axis.
