Order of solving definite integrals I've been coming across several definite integrals in my homework where the solving order is flipped, and am unsure why.  Currently, I'm working on calculating the area between both intersecting and non-intersecting graphs.
According to the book, the formula for finding the area bounded by two graphs is
$$A=\int_{a}^{b}f(x)-g(x) \mathrm dx$$
For example, given $f(x)=x^3-3x^2+3x$ and $g(x)=x^2$, you can see that the intersections  are  $x={0, 1, 3}$ by factoring.  So, at first glance, it looks as if the problem is solved via
$$\int_0^1f(x)-g(x)\mathrm dx+\int_1^3f(x)-g(x)\mathrm dx$$
However, when I solved using those integrals, the answer didn't match the book answer, so I took another look at the work.  According to the book, the actual integral formulas are
$$\int_0^1f(x)-g(x)\mathrm dx+\int_1^3g(x)-f(x)\mathrm dx$$
I was a little curious about that, so I put the formulas in a grapher and it turns out that $f(x)$ and $g(x)$ flip values at the intersection $x=1.$
So how can I determine which order to place the $f(x)$ and $g(x)$ integration order without using a graphing utility?  Is it dependent on the intersection values?
 A: Note that the correct formula for area is
$$A = \int_a^b \Bigl| f(x)-g(x)\Bigr|\,dx$$
(note the absolute value bars!) That means that you need to be careful with which function is larger and which function is smaller at any given interval.
Since the graphs intersect at $0$, at $1$, and at $3$, and nowhere else, and the functions are continuous, that means that the only places where the function can switch "who is on top" are $0$, $1$ and $3$. 
That means that on $(-\infty,0]$, you always have the same function "on top"; likewise, the functions don't cross on $[0,1]$, and the don't cross on $[1,3]$. 
So, just plug in any number between $0$ and $1$ to see whcih one is bigger on that interval. At $\frac{1}{2}$, you have $f(\frac{1}{2}) = 0.875$, $g(\frac{1}{2}) = 0.25$; since $f(\frac{1}{2})\gt g(\frac{1}{2})$, on $[0,1]$ you have $f\geq g$, so on $[0,1]$ we have
$$\Bigl| f(x) - g(x) \Bigr| = f(x)-g(x).$$
To see what happens on $[1,3]$, plug in any number in $[1,3]$; e.g., plugging in $x=2$, we have $f(2) = 2$, $g(2) = 4$, so on this interval we have $g\geq f$, hence on $[1,3]$ we have
$$\Bigl| f(x)-g(x)\Bigr| = g(x)-f(x).$$
A: Arturo and wckronholm have already offered a simple, practical way to determine where $|f(x)-g(x)|$ is $f(x)-g(x)$ and where it’s $g(x)-f(x)$, but you really ought to be familiar with sign analysis as well.
As you already discovered, $f(x)-g(x)=x^3-4x^2+3x=x(x-1)(x-3)$. These three factors change sign at $0$, $1$, and $3$, respectively; none of them changes sign within any of the intervals $(-\infty,0)$, $(0,1)$, $(1,3)$, and $(3,\infty)$. On $(-\infty,0)$ all three factors are negative; on $(0,1)$ the factor $x$ is positive and the other two are negative; on $(1,3)$ the factors $x$ and $x-1$ are positive and $x-3$ is negative; and on $(3,\infty)$ all three are positive. The product $x(x-1)(x-3)$ is therefore negative on $(-\infty,0)$, positive on $(0,1)$, negative on $(1,3)$, and positive on $(3,\infty)$. That tells you that $|f(x)-g(x)|=f(x)-g(x)$ when $0<x<1$ or $x>3$, and $|f(x)-g(x)|=g(x)-f(x)$ when $x<0$ or $1<x<3$. (Of course $|f(x)-g(x)|=f(x)-g(x)=g(x)-f(x)=0$ when $x$ is $0$, $1$, or $3$.)
A: You are, I hope, not quoting your calculus book correctly.
The correct result is:
Suppose that $f(x) \ge g(x)$ in the interval from $x=a$ to $x=b$.  Then the area of the region between the curves $y=f(x)$ and $y=g(x)$, from the line $x=a$ to the line $x=b$, is equal to
$$\int_a^b(f(x)-g(x))\,dx.$$
The condition $f(x)-g(x) \ge 0$ is essential here.
In your example, from $x=0$ to $x=1$ we have $f(x) \ge g(x)$, so the area from $0$ to $1$ is indeed
$\int_0^1 (f(x)-g(x))\, dx$.
However, from $x=1$ to $x=3$, we have $f(x) -g(x) \le 0$, the curve $y=g(x)$ lies above the curve $y=f(x)$.  So the area of the region between the two curves, from $x=1$ to $x=3$, is $\int_1^3(g(x)-f(x))\,dx$.
To find the full area, add up.
Comment: When you calculate $\int_a^b h(x)\,dx$, the integral cheerfully "adds up" and does not worry about whether the things it is adding up are positive or negative.  This often gives exactly the answer we need. For example, if $h(t)$ is the velocity at time $t$, then $\int_a^bh(t)\,dt$ gives the net displacement (change of position) as time goes from $a$ to $b$. The integral takes account of the fact that when $h(t)<0$, we are going "backwards."
If we wanted the total distance travelled, we would have to treat the parts where $h(t) \le 0$ and the parts where $h(t)\ge 0$ separately, just as we had to in the area case. 
For determining where $f(x)-g(x)$ is positive, negative, we can let $h(x)=f(x)-g(x)$, and try to find where $h(x)$ is positive, negative.  A continuous function $h(x)$ can only change sign where $h(x)=0$. (It need not change sign there.  For example, if $h(x)=(x-1)^2$, then $h(1)=0$, but $h(x)$ does not change sign at $x=1$.)
If the solutions of $h(x)=0$ are easy to find, we can quickly determine all the places where there might be a change of sign, and the rest is straightforward. Otherwise, a numerical procedure has to be used to approximate the roots.
A: One approach is to integrate $\int_a^b |f(x)-g(x)|\;dx$, but in practice this usually means you need to know which of $f$ and $g$ is the larger function, which could change at some points in the interval $[a,b]$. One method of determining this behavior is to graph the functions. But this can also be done without graphing.
Suppose $f$ and $g$ are continuous on $[a,b]$ and that $f(a)=g(a)$ and $f(b)=g(b)$ and $f(x) \neq g(x)$ on $(a,b)$. By continuity, the function $f-g$ is either non-negative on $(a,b)$ or non-positive on $(a,b)$. We can determine which by choosing and value $c$ between $a$ and $b$.
So, in your example, to determine which function is greater on the interval $[0,1]$ we can choose to evaluate each function at $1/2$: $f(1/2)=7/8$ and $g(1/2)=1/4$. Thus $f \geq g$ on $[0,1]$ and so the area is $\int_0^1 f(x)-g(x)\;dx$ on this interval.
You can repeat this process on each interval between points of intersection.
A: If you know they intersect at 0, 1, and 3 and have no discontinuities (since they're polynomials), you can just plug some number between 0 and 1 into both $f$ and $g$ and see which one is bigger, and also some number between 1 and 3.  You certainly don't need a graphing utility to do that.
