Chapter 4. Integration

Chapter 4. Integration

4.1 Definite and indefinite integrals

Because any formula can be differentiated symbolically to find another formula, the main motivation for doing derivatives numerically would be if the function to be differentiated wasn't known in symbolic form. A typical example might be a two-person network computer game, in which player A's computer needs to figure out player B's velocity based on knowledge of how her position changes over time. But in most cases, it's numerical integration that's interesting, not numerical differentiation.

As a warm-up, let's see how to do a running sum of a discrete function using Yacas. The following program computes the sum 1+2+…+100 discussed to on page 7. Now that we're writing real computer programs with Yacas, it would be a good idea to enter each program into a file before trying to run it. In fact, some of these examples won't run properly if you just start up Yacas and type them in one line at a time. If you're using Adobe Reader to read this book, you can do Tools>Basic>Select, select the program, copy it into a file, and then edit out the line numbers.

Example 1
\nn n := 1;
\nn sum := 0;
\nn While (n<=100) [
\nn   sum := sum+n;
\nn   n := n+1;
\nn ];
\nn Echo(sum);

The semicolons are to separate one instruction from the next, and they become necessary now that we're doing real programming. Line 1 of this program defines the variable n, which will take on all the values from 1 to 100. Line 2 says that we haven't added anything up yet, so our running sum is zero so far. Line 3 says to keep on repeating the instructions inside the square brackets until n goes past 100. Line 4 updates the running sum, and line 5 updates the value of n. If you've never done any programming before, a statement like n:=n+1 might seem like nonsense --- how can a number equal itself plus one? But that's why we use the := symbol; it says that we're redefining n, not stating an equation. If n was previously 37, then after this statement is executed, n will be redefined as 38. To run the program on a Linux computer, do this (assuming you saved the program in a file named sum.yacas):

% yacas -pc sum.yacas
5050

Here the \verb@One way of stating this result is The capital Greek letter Σ, sigma, is used because it makes the “s” sound, and that's the first sound in the word “sum.” The n=1 below the sigma says the sum starts at 1, and the 100 on top says it ends at 100. The n is what's known as a dummy variable: it has no meaning outside the context of the sum. Figure a shows the graphical interpretation of the sum: we're adding up the areas of a series of rectangular strips. (For clarity, the figure only shows the sum going up to 7, rather than 100.) a / Graphical interpretation of the sum 1+2+…+7.

Now how about an integral? Figure b shows the graphical interpretation of what we're trying to do: find the area of the shaded triangle. This is an example we know how to do symbolically, so we can do it numerically as well, and check the answers against each other. Symbolically, the area is given by the integral. To integrate the function x·(t)=t, we know we need some function with a t2 in it, since we want something whose derivative is t, and differentiation reduces the power by one. The derivative of t2 would be 2t rather than t, so what we want is x(t)=t2/2. Let's compute the area of the triangle that stretches along the t axis from 0 to 100: x(100)=1002/2=5000. b / Graphical interpretation of the integral of the function x·(t)=t.

Figure c shows how to accomplish the same thing numerically. We break up the area into a whole bunch of very skinny rectangles. Ideally, we'd like to make the width of each rectangle be an infinitesimal number dx, so that we'd be adding up an infinite number of infinitesimal areas. In reality, a computer can't do that, so we divide up the interval from t=0 to t=100 into H rectangles, each with finite width dt=100/H. Instead of making H infinite, we make it the largest number we can without making the computer take too long to add up the areas of the rectangles. c / Approximating the integral numerically.

Example 2
\nn tmax := 100;
\nn H := 1000;
\nn dt := tmax/H;
\nn sum := 0;
\nn t := 0;
\nn While (t<=tmax) [
\nn   sum := N(sum+t*dt);
\nn   t := N(t+dt);
\nn ];
\nn Echo(sum);

In example 51, we split the interval from t=0 to 100 into H=1000 small intervals, each with width dt=0.1. The result is 5,005, which agrees with the symbolic result to three digits of precision. Changing H to 10,000 gives 5,000.5, which is one more digit. Clearly as we make the number of rectangles greater and greater, we're converging to the correct result of 5,000.

In the Leibniz notation, the thing we've just calculated, by two different techniques, is written like this: It looks a lot like the Σ notation, with the Σ replaces by a flattened-out letter “S.” The t is a dummy variable. What I've been casually referring to as an integral is really two different but closely related things, known as the definite integral and the indefinite integral.

Definition of the indefinite integral

If x· is a function, then a function x is an indefinite integral of x· if, as implied by the notation, dx/dt=x·.

Interpretation: Doing an indefinite integral means doing the opposite of differentiation. All the possible indefinite integrals are the same function except for an additive constant.

Example 3

◊ Find the indefinite integral of the function x·(t)=t.

◊ Any function of the form

x(t)=t2/2+c ,

where c is a constant, is an indefinite integral of this function, since its derivative is t.

Definition of the definite integral

If x· is a function, then the definite integral of x· from a to b is defined as  where Δ t=(b-a)/H.

Interpretation: What we're calculating is the area under the graph of x·, from a to b. (If the graph dips below the t axis, we interpret the area between it and the axis as a negative area.) The thing inside the limit is a calculation like the one done in example 51, but generalized to a≠ 0. If H was infinite, then Δ t would be an infinitesimal number dt.