Some appliations of the "summation method"

Initialization cell.  Execute this group of cells before beginning

Left endpoint approximation

\(\(\(leftrect[n_] := 
        Block[{X, dX, rectangles, boundaries, RightRect, \ leftsum, \ label, 
            aloc, \ bloc, floc}, 
aloc\  = \ 
            a; 
bloc\  = \ b; 
floc\  = \ 
            f; 
functionplot := 
            Plot[floc[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 = \(bloc - aloc\)\/n; 
          X = Table[a + \(i\ \((bloc - aloc)\)\)\/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[floc, 
                  X[[j]], dX], {j, 1, 
                  n}]]; leftsum = 
            N[∑\+\(i = 1\)\%n floc[
                    X[[i]]]\ dX, 10]; 
          label = leftsum\ "=  sum of  rectangle areas "; 
          Show[{functionplot, \ rectangles, boundaries, \ functionplot}, 
            PlotLabel -> label, 
            Frame\  -> \ 
              True, \ \ DisplayFunction -> $DisplayFunction];];\)\(
\)
    \)\)
\(\(leftrect[f_, \ a_, \ b_, \ n_]\  := \ 
        Module[{X, dX, rectangles, boundaries, RightRect, \ leftsum, \ label, 
            floc, \ aloc, \ bloc}, 
aloc\  = \ 
            a; 
bloc\  = \ b; 
floc\  = \ 
            f; 
functionplot := 
            Plot[floc[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 = \(bloc - aloc\)\/n; 
          X = Table[a + \(i\ \((bloc - aloc)\)\)\/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[floc, 
                  X[[j]], dX], {j, 1, 
                  n}]]; leftsum = 
            N[∑\+\(i = 1\)\%n floc[
                    X[[i]]]\ dX, 10]; 
          label = leftsum\ "=  sum of  rectangle areas "; 
          Show[{functionplot, \ rectangles, boundaries, \ functionplot}, 
            PlotLabel -> label, 
            Frame\  -> \ 
              True, \ \ DisplayFunction -> $DisplayFunction];];\)


\)
leftsum[n_]  :=  
        Block[{X, dX, rectangles, boundaries, 
            RightRect}, 
aloc  =  
            a; 
bloc  =  
            b; 
dX = ((bloc - aloc)/n); 
X = 
            Table[a + ((i (bloc - aloc))/n), {i, 0, 
                n}]; 

N[(∑_(i = 1)^n) f[X[[i]]] dX, 
            10]];

    
leftsum[f_,  a,  b_,  n_]  := 
        Block[{X, dX, rectangles, boundaries, 
            RightRect}, 
aloc  =  
            a; 
bloc  =  
            b; 
dX = ((bloc - aloc)/n); 
X = 
            Table[a + ((i (bloc - aloc))/n), {i, 0, 
                n}]; 

N[(∑_(i = 1)^n) f[X[[i]]] dX, 
            10]];

Midpoint approximation

Clear[midrect,  midsum];

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

N[(∑_(i = 1)^n) f[X[[i]]  +  dX/2] dX, 
            10]];

midsum[f_,  a_,  b_,  n_]  := 
        Block[{X, dX, rectangles, boundaries, 
            RightRect}, 
aloc  =  
            a; 
bloc  =  
            b; 
dX = ((bloc - aloc)/n); 
X = 
            Table[a + ((i (bloc - aloc))/n), {i, 0, 
                n}]; 

N[(∑_(i = 1)^n) f[X[[i]] +  dX/2] dX, 
            10]];

Right endpoint approximation

\(\(rightrect[n_] := 
        Block[{X, dX, rectangles, boundaries, RightRect, \ floc, \ aloc, \ 
            bloc, h}, 
floc\  = \ 
            f; 
aloc\  = \ a; 
bloc\  = \ 
            b; 
h\  = \ 
            b - a; 
functionplot := 
            Plot[floc[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 = h\/n; 
          X = Table[a + \(i\ \((h)\)\)\/n, {i, 0, n}]; 
          rectangles := 
            Graphics[{GrayLevel[0.9], 
                Table[Rectangle[{X[[i]], 
                      0}, {X[[i + 1]], 
                      floc[X[[i + 
                            1]]]}], {i, 1, n}]}]; 
          boundaries := 
            Graphics[
              Table[RightRect[floc, 
                  X[[j]], dX], {j, 1, 
                  n}]]; rightsum = 
            N[∑\+\(i = 1\)\%n floc[
                    X[[i + 1]]]\ dX, 
              10]; label = rightsum\ "=  sum of area of rectangles "; 
          Show[{functionplot, \ rectangles, boundaries, functionplot}, 
            PlotLabel -> 
              label, 
DisplayFunction -> $DisplayFunction];];\)\)
\(\(rightrect[f_, \ a_, \ b_, \ n_] := 
        Block[{X, dX, rectangles, boundaries, RightRect, \ floc, \ aloc, \ 
            bloc, h}, 
floc\  = \ 
            f; 
aloc\  = \ a; 
bloc\  = \ 
            b; 
h\  = \ 
            b - a; 
functionplot := 
            Plot[floc[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 = h\/n; 
          X = Table[a + \(i\ \((h)\)\)\/n, {i, 0, n}]; 
          rectangles := 
            Graphics[{GrayLevel[0.9], 
                Table[Rectangle[{X[[i]], 
                      0}, {X[[i + 1]], 
                      floc[X[[i + 
                            1]]]}], {i, 1, n}]}]; 
          boundaries := 
            Graphics[
              Table[RightRect[floc, 
                  X[[j]], dX], {j, 1, 
                  n}]]; rightsum = 
            N[∑\+\(i = 1\)\%n floc[
                    X[[i + 1]]]\ dX, 
              10]; label = rightsum\ "=  sum of area of rectangles "; 
          Show[{functionplot, \ 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]]

Compute the area between the curve y = (x-3)^2 + 2 and the x axis.

First the graph:

f[x_]  :=  -(x - 3)^2 + 
        2

    Plot[f[x],  {x,  1,  5}]

Find the points of intersection with the x axis:

{a,  b}  =  
      x /.  Solve[f[x]  == 0,  x]

midrect[20]
midrect[100]
midrect[500]

We can conclude that the desired area is approximately 3.7712.

Compute the volume of a sphere of radius 1.

Programming

Needs["Graphics`SurfaceOfRevolution`"];
Needs["Utilities`FilterOptions`"];
<< Graphics`Shapes`


    
Clear[f];
f[x_]  :=  (Sqrt[1 - x^2])

    
disk[r_, v_,  n_]  :=  
        Graphics3D[
          Polygon[Table[{r*Cos[s*2  π/n],  r*Sin[s*2 π/n],  
                  0}  +  v,  {s,  1,  
                n}]]];
closedcylinder[r_,  h_,  n_,  v_]  :=  
        Module[{g1, g2,  
            g3}, 
g1  =   Graphics3D[
              TranslateShape[Cylinder[r, h, n],  
                v]]; 
g2  =  
            disk[r,  v +  {0, 0, h},  n]; 
g3  =  
            disk[r,  v -  {0, 0, h},  n]; 
{g1, g2,  
            g3}
];

    
SlicedSphere[n_]  :=  
      Module[{c}, 
c  =  
          Flatten[Table[
              closedcylinder[f[(k + 1/2)/n], 1/(2  n),  
                100,    {0, 0,  (k + 1/2)/n}],  {k,  -n,  
                n - 1}], 1]; 
Show[c,  
          BoxRatios  ->  {1, 1, 1},  Axes ->  True, 
          ViewPoint -> {-3.101,  -2.603,  
              1.421}]
]

We put the sphere through a meat slicer, and replace each slice by a perfect disk.
A sphere approximated by a stack of disks looks like this:

SlicedSphere[5]
SlicedSphere[10]

The volume of the stack of disks is (∑_(i = 1)^n) π (1 - 
              (Subscript[x, i]^2)) Δ(Subscript[x, i]), where Δ(Subscript[x, i]) is the thickness of the ith disk, and (Sqrt[1 - (Subscript[x, i]^2)]) is the radius of the ith disk.  

This sum is the  is the same same sum that  we would use to approximate  the area under the curve 
g(x) = π (1 - (x^2)), between x = -1 and x = 1.

The procedure midsum below computes the sum with (Subscript[x, i]) equal to the midpoint of each subinterval.

f[x_] := π (1 - (x^2))
midsum[f,  -1,  1,  5]
midsum[f,  -1,  1,  20]
midsum[f, -1, 1,  200]
midsum[f,  -1, 1,  500] 
midsum[f,  -1, 1, 1000] 
  N[((4 π)/3)]

It appears by comparing the computed quantity with ((4 π)/3) that the volume of a sphere of radius 1 is ((4 π)/3).    We expect volume to grow as the cube of the radius, so the volume of a cube of radius R will be (1/3) (4 π) (R^3)

Limit of sums for a negative function gives negative area:

f[x_]  :=  -x^3 
midrect[f,  0,  3,  500]

g[x_]  =  x^3;
midrect[g,  0, 3,  500]

Limit of Sums for a general (not everywhere positive, not everywhere negative) function gives  "sum of signed areas".

f[x_]  :=  
      x^3  -  4  x^2  + 5

    Plot[f[x],  {x,  -3,  7}]

midrect[f,  -2,  4,  20]
midrect[f,  -2,  4,  100]
midrect[f,  -2,  4,  500]
midrect[f,  -2,  4,  1000]

Integrate[f[x],  {x, -2, 4}]