What Is Area? -- Introduction to the Integral

Important:  To view this notebook, first go to the "kernel" menu, choose "evaluation" and then "evaluate notebook".  I have removed all the output from this notebook to conserve space.

Initialization cell.  Execute this group of cells before beginning

Left endpoint approximation

leftrect[n_] := 
        Block[{X, dX, rectangles, boundaries, RightRect}, 
          functionplot := 
            Plot[f[x], {x, a, b}, DisplayFunction -> Identity, 
              PlotRange -> All]; 
          RightRect[g_, x_, d_] := 
            Line[{{x, 0}, {x + d, 0}, {x + d, g[x]}, {x, g[x]}, {x, 0}}]; 
          dX = ((b - a)/n); X = Table[a + ((i (b - a))/n), {i, 0, n}]; 
          rectangles := 
            Graphics[{GrayLevel[0.9], 
                Table[Rectangle[{X[[i]], 
                      0}, {X[[i + 1]], 
                      f[X[[i]]]}], {i, 
                    1, n}]}]; 
          boundaries := 
            Graphics[
              Table[RightRect[f, X[[j]], 
                  dX], {j, 1, n}]]; 
          leftsum = 
            N[(∑_(i = 1)^n) f[
                    X[[i]]] dX, 10]; 
          label = leftsum "=  sum of  rectangle areas "; 
          Show[rectangles, boundaries, functionplot, PlotLabel -> label, 
            DisplayFunction -> $DisplayFunction];];

Midpoint approximation

midrect[n_] := 
        Block[{X, dX, rectangles, boundaries, MidRect}, 
          functionplot := 
            Plot[f[x], {x, a, b}, DisplayFunction -> Identity, 
              PlotRange -> All]; 
          MidRect[g_, x_, d_] := 
            Line[{{x, 0}, {x + d, 0}, {x + d, g[x + (d/2)]}, {x, 
                  g[x + (d/2)]}, {x, 0}}]; dX = ((b - a)/n); 
          X = Table[a + ((i (b - a))/n), {i, 0, n}]; 
          rectangles := 
            Graphics[{GrayLevel[0.9], 
                Table[Rectangle[{X[[i]], 
                      0}, {X[[i + 1]], 
                      f[X[[i]] + 
                          (dX/2)]}], {i, 1, n}]}]; 
          boundaries := 
            Graphics[
              Table[MidRect[f, X[[j]], 
                  dX], {j, 1, n}]]; 
          midsum = 
            N[(∑_(i = 1)^n) f[
                    X[[i]] + (dX/2)] dX, 
              10]; label = midsum "= sum  of rectangle areas"; 
          Show[rectangles, boundaries, functionplot, PlotLabel -> label, 
            DisplayFunction -> $DisplayFunction];];

Right endpoint approximation

rightrect[n_] := 
        Block[{X, dX, rectangles, boundaries, RightRect}, 
          functionplot := 
            Plot[f[x], {x, a, b}, DisplayFunction -> Identity, 
              PlotRange -> All]; 
          RightRect[g_, x_, d_] := 
            Line[{{x, 0}, {x + d, 0}, {x + d, g[x + d]}, {x, g[x + d]}, {x, 
                  0}}]; dX = ((b - a)/n); 
          X = Table[a + ((i (b - a))/n), {i, 0, n}]; 
          rectangles := 
            Graphics[{GrayLevel[0.9], 
                Table[Rectangle[{X[[i]], 
                      0}, {X[[i + 1]], 
                      f[X[[i + 
                            1]]]}], {i, 1, n}]}]; 
          boundaries := 
            Graphics[
              Table[RightRect[f, X[[j]], 
                  dX], {j, 1, n}]]; 
          rightsum = 
            N[(∑_(i = 1)^n) f[
                    X[[i + 1]]] dX, 
              10]; label = rightsum "=  sum of area of rectangles "; 
          Show[rectangles, boundaries, functionplot, PlotLabel -> label, 
            DisplayFunction -> $DisplayFunction];];

Trapezoid approximation

trapezoids[n_] := 
        Block[{X, dX, Trap, regions, boundaries}, 
          functionplot := 
            Plot[f[x], {x, a, b}, DisplayFunction -> Identity, 
              PlotRange -> All]; dX = ((b - a)/n); 
          X = Table[a + ((i (b - a))/n), {i, 0, n}]; 
          Trap[g_, x_, d_] := 
            Line[{{x, 0}, {x + d, 0}, {x + d, g[x + d]}, {x, g[x]}, {x, 0}}]; 
          regions := 
            Graphics[{GrayLevel[0.9], 
                Table[Polygon[{{X[[i]], 
                        0}, {X[[i]], 
                        f[X[[
                            i]]]}, {X[[
                          i + 1]], 
                        f[X[[i + 
                              1]]]}, {X[[
                          i + 1]], 0}}], {i, 1, n}]}]; 
          boundaries := 
            Graphics[
              Table[Trap[f, X[[j]], 
                  dX], {j, 1, n}]]; 
          trapsum = 
            N[(1/2) dX (f[a] + 
                    2 (∑_(i = 2)^n) f[
                          X[[i]]] + 
                    f[b]), 10]; 
          label = trapsum "= sum of area of trapezoids"; 
          Show[regions, boundaries, functionplot, PlotLabel -> label, 
            DisplayFunction -> $DisplayFunction];];

Numerical rules

LeftSum[n_] := 
      Block[{dX}, dX = ((b - a)/n); 
        N[(∑_(i = 0)^(n - 1))dX f[a + i dX], 10]]
MidpointSum[n_] := 
      Block[{dX}, dX = ((b - a)/n); 
        N[(∑_(i = 0)^(n - 1))dX f[a + (i + 0.5) dX], 
          10]]
RightSum[n_] := 
      Block[{dX}, dX = ((b - a)/n); 
        N[(∑_(i = 1)^n) dX f[a + i dX], 10]]
TrapezoidSum[n_] := 
      Block[{dX}, dX = ((b - a)/n); 
        N[(∑_(i = 0)^(n - 1))dX 0.5 (f[a + i dX] + 
                  f[a + (i + 1) dX]), 10]]

Demonstration.

We know what is meant by the area of a polygon, and in particular the area of a rectangle or a triangle,  but it is not altogether obvious what is meant by the area of a plane figure with a curved boundary.   Here we explore the concept of the area under the graph of a non-negative function.  What, for example is meant by the area under the graph of y = (x^2) between x = 1  and x = 3?

Our procedure for defining the area under the graph of  f[x] = (x^2) is to approximate it by the area of many rectangles.  Refer to the following diagram.

We divide the original interval into a number of subintervals.  In each subinterval we choose one point  x* and we consider a  new function  g  which is constant on the subinterval,  with value f(x*).  The graph of the function g is like a staircase, so we call it a step function.    The area under the graph of  the step function  g   is an approximation to the area under the graph of  the original function f.   The area under the graph of the step function  g  is easy to determine:  it is the sum of the areas of a number of rectangles.  

If the point chosen in the ith subinterval is called x*(i)  and the width of the ith subinterval is Dx(i),   then the  area of the  ith rectangle is   
f(x*(i)) Dx(i),  
and the area under the graph of the step function   g   is the sum  of these areas. Such a sum is called a Riemann sum.

Here we have produced the step function  g  and the approximation to the area under the graph of  f  by a very particular procedure:  we have divided the original interval  [a,b]  into  20  subintervals of equal length, and in each subinterval, we have chosen the left endpoint as our special point  x*.    You can see that our approximation to the area will be too small.

f[x_] := (x^2)
a = 1;
b = 3;
leftrect[20]

If we replace  20  by a larger number   n    and  construct  the approximation in the same way, the step function will approximate the original function more closely and the  approximation to the area ought to be closer to the "correct"  answer.   Here we are going to obtain the graphs  and approximate areas  for  n = 50 and n = 100.

In the initialization of this notebook,  a Mathematica function 
leftrect[ n]  
is defined   which  draws a the graph of  the original function  f   together with the graph of a step function   g  with n   steps,  and computes the area under the step function  g.   The original interval [a,b]  is divided into  n  subintervals   equal length  and in each  subinterval, the  left endpoint is chosen as the special point  x*.

leftrect[20]
leftrect[50]
leftrect[100]

You can see  that each of  these approximations is too small, but the approximations are getting better as we take more and shorter  subintervals.   It is a a fact  (that is, a theorem)  that the approximations approach a limit as the number  n   of subintervals goes to infinity (and the length of the subintervals goes to zero).  This limit is the area under the graph of  f.  That is, area is defined as a limit.

Let's get a Mathematica formula for the  approximate area obtained by using  n  subintervals.
Note  that the left end of the  ith subinterval is 
 a + (i-1)*((b - a)/n)  
 and the width of each subinterval is
   ((b - a)/n),  
   so the area under the step function is  the sum of the numbers
 ((b - a)/n)* f(a + (i-1)*((b - a)/n))  
 for i = 1,2,...n.   The Mathematica notation for summation is   
 Sum[ expression, {index, start, end}],   
 so we can compute the approximation  corresponding to n subintervals as follows:

LeftSum[n_] := 
      N[(∑_(i = 0)^(n - 1))(((b - a) f[a + ((i (b - a))/n)])/n)]

We  compute the approximate areas for a couple of values  of n:

LeftSum[20]
LeftSum[50]
LeftSum[100]

The  following cell  makes a table of approximate areas for several values of n.  Execute it now!

TableForm[Table[{n, LeftSum[n]}, {n, 500, 4000, 500}]]

It turns out that the actual area under the graph of  f is   8 + 2/3.  You can see that even with several thousand subintervals, we haven't obtained a very accurate approximation (and it took a long time to do the computations.)   There are very simple adjustments to our procedure which will  produce better approximations with less computation time.  We will eventually consider several such adjustments.

For now, let's observe that if we took the right endpoint in each subinterval, we would get approximations to the area which are too large.  If we take the midpoint in each subinterval, we stand a better chance of getting a more accurate approximation. Let's try it:

midrect[20]
midrect[50]
midrect[100]

TableForm[Table[{n, MidpointSum[n]}, {n, 100, 1000, 200}]]

Indeed, in this example, we got much better approximations with less machine computation using the "midpoint rule."

Let's try some additional examples.  Let's find the area under the curve
y = x^4, between x = 0 and x = 5.

f[x_]  =  x^3;
a  =  0;
b  =   .5;

midrect[20]

TableForm[Table[{n, MidpointSum[n]}, {n, 100, 1000, 200}]]

Area is defined to be the limit of Riemann sums, as the width of the subintervals goes to zero (and hence the total number of subintervals goes to infinity).  We really don't have any other choice!  We don't have some intrinsic and computable notion of area, so we have to make some sort of definition of area by approximations.

We can apply the same procedure (computing Riemann sums, and testing what happens as the width of the subintervals goes to zero) for functions which are not necessarily non-negatiive.  The result, which is called the integral can be regarded as an algebraic sum of signed areas:

f[x_]  :=  (x^3) - 3 x - 1
a  =  -1;
b  =  2;

midrect[20]
midrect[100]

TableForm[Table[{n, MidpointSum[n]}, {n, 100, 1000, 200}]]

The integral of a function f[x] over an interval [a,b] is denoted
(∫_a^b) f(x) dx.

Thus,  we have just computed numerical approximations to
(∫_(-1)^2) (x^3) - 3 x - 
            1 dx,  and our guess is that

(∫_(-1)^2) (x^3) - 3 x - 
              1 dx  =  - 3.75.

Integrals can be used to compute all sorts of things, not just areas: for example, integrals are used to compute volumes, work, mass, center of mass, length of curves, areas of surfaces, etc., etc.

As I will explain in class, the volume of a right circular cone with height h and radius r is

π ((r^2) /
              (h^2)) (∫_0^h) (x^2) dx

Furthermore,   (∫_0^h) (x^2) dx = ((h^3)/3)
so we recover (or justify for the first time) the usual formula for the volume,
 V = (1/3) π (r^2) h.
 Let's test the formula (∫_0^h) (x^2) dx = ((h^3)/3) by the example h = 4

f[x_]  :=  x^2
a  =  0;
b  =  4;

TableForm[Table[{n, MidpointSum[n]}, {n, 100, 1000, 200}]]