## 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 50

  1  n := 1;
2  sum := 0;
3  While (n<=100) [
4  sum := sum+n;
5  n := n+1;
6  ];
7  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 % symbol is the computer's prompt. The result is 5,050, as expected. One way of stating this result is

$\sum_{n=1}^{100} n = 5050 .$

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.)

Figure 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 $$\dot{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.

Figure B. Graphical interpretation of the integral of the function $$\dot{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.

Figure C. Approximating the integral numerically.

#### Example 51

  1  tmax := 100;
2  H := 1000;
3  dt := tmax/H;
4  sum := 0;
5  t := 0;
6  While (t<=tmax) [
7  sum := N(sum+t*dt);
8   t := N(t+dt);
9  ];
10  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:

$\int_{0}^{100} t dt = 5,000$

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 $$\dot{x}$$ is a function, then a function x is an indefinite integral of $$\dot{x}$$ if, as implied by the notation, $$dx/dt=\dot{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 52

◊ Find the indefinite integral of the function $$\dot{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 $$\dot{x}$$ is a function, then the definite integral of $$\dot{x}$$ from a to b is defined as

\begin{align} & \int_{a}^{b} \dot{x}(t) dt \\ &= \lim_{H\rightarrow\infty} \sum_{i=0}^{H} \dot{x}\left(a+i\Delta t\right)\Delta t , \end{align}

where Δt = (b-a)/H.

Interpretation: What we're calculating is the area under the graph of $$\dot{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.