Sums with Mathematica

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Notebook Overview

This NoteBook introduces summation in Mathematica notation and is used to compute some Riemann sums approximating integrals.

References to the Text

This NoteBook goes with Chapter 12 of the text.

Step-by-step

Some sums starting with the sum 1 + 1 + ... + 1

The Mathematica  command to sum is
	Sum[<thing to sum>, {<index>, <start>,<finish>,<step>}]
This can be entered either in conventional mathematical notation or with "Sum."  Our first example sums  1 (at x=0), plus 1 (at x=1):

dx = 1;
(∑_({{x = 0}, {Δ x = dx}})^1)1Sum[1, {x, 0, 1, dx}]

Now we change the step  dx  to dx = 1/2, so that the index takes the values 0, 1/2, 1.

dx = (1/2);
(∑_({{x = 0}, {Δ x = dx}})^1)1

Practice Exercises

1.  How much will we get when dx = 1/3? (Press enter to check your work.)

dx = (1/3);
(∑_({{x = 0}, {Δ x = dx}})^1)1

2.  How much will we get when we change the finish value?

dx = (1/3);
(∑_({{x = 0}, {Δ x = dx}})^3)1

3.  How much will we get when we change the start value?

dx = (1/3);
(∑_({{x = 2}, {Δ x = dx}})^3)1

4. How does the sum of  1  depend on the endpoints  a  and  b in  

			(∑_({{x = a}, {Δ x = dx}})^(b - dx))1 = Sum[ 1 , {x,a,b-dx,dx}]?

a = 1;
b = 3;
dx =  .01;
(∑_({{x = a}, {Δ x = dx}})^(b - dx))1

Clear[a, b, dx];
(∑_({{x = a}, {Δ x = dx}})^(b - dx))1

?? Floor

The Sum  dx + dx + dx + ... + dx

The sum

Sum[ 1 ,{x,a,b-dx,dx}]

starts at  x = a and takes steps of size  dx  until it gets to  just below  b-dx.  This means that there are  approximately  (b-a)/dx  terms in the sum.  In fact there are the integer part of the number (b - a)/dx  terms in the sum.  If  dx  divides  b-a  exactly, this is an integer and otherwise not.  The point of this is that

		(∑_({{x = a}, {Δ x = dx}})^(b - dx))dx = Sum[ dx , {x,a,b-dx,dx}] = 
		dx* (∑_({{x = a}, {Δ x = dx}})^(b - dx))1 = dx*Sum[ 1 , {x,a,b-dx,dx}]
		
		 ≈ dx * (b-a)/dx = b-a
		 
Check it out:

dx = (1/10); a = 1; b = 5; (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

dx = (1/100); a = 1; b = 5; (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

dx = (1/1000); a = 1; b = 5; (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

dx =  .03; a = 1; b = 5; (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

dx =  .003; a = 1; b = 5; (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

Clear[a, b, dx];
(∑_({{x = a}, {Δ x = dx}})^(b - dx))dx

Practice Exercises

1)  Compute  (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx = Sum[ dx , {x, a, b-dx, dx}]  when  a = 2, b = 7 and  dx takes several successively smaller values that divide the interval  [2,7]  exactly.  What is the limiting value as  dx -> 0?  Why?

2)  Compute  (∑_({{x = a}, {Δ x = dx}})^(b - dx))dx = Sum[ dx , {x, a, b-dx, dx}]  when  a = 2, b = 7 and  dx takes several successively smaller values that do not divide the interval  [2,7]  exactly.  Why arent the sums equal to  b-a?  What is the limiting value as  dx -> 0?  Why?

3)  Show that the following sum gives the answer  b-a  when  dx  divides the interval  [a,b]  exactly:

	(∑_({{x = a + dx/2}, {Δ x = dx}})^(b - dx/2))dx = Sum[ dx , {x, a+dx/2, b-dx/2, dx}] = b - a

The sum 1/10 1/10 + 2/10 1/10 + ⋯ + 9/10 1/10 & (∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

This section helps you understand the sum

	(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx = Sum[ x dx ,{x,a,b-dx,dx}]
	
The first example is  1/10 X 1/10 + 2/10 X1/10 + 3/10 X1/10 + ... + 9/10X1/10

dx = (1/10);
(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

If you would rather have the decimal approximation, do it this way:

dx =  .1;
(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

Next sum  1/100X1/100 + 2/100X1/100 + 3/100X1/100 + ....+ 99/100X1/100 + 1/100

dx =  .01;
(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

Clear[dx];
(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

Practice Exercises

1.  How much will we get when dx = 1/1000? (Press enter to check your work.)

dx = (1/1000);
(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

2. What is your guess at Limit[Sum[x dx,{x,0,1-dx,dx}]  as  dx tends to zero?

3. How does the sum of  x dx  depend on the endpoints?

a = 1;
b = 3;
dx =  .01;
(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx

Clear[a, b, dx];
(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx

MidPoint Sums

When we want to approximate the

Limit[ Sum[ f[x] dx ] 
	
over a range of  x  as  dx  tends to zero, it is more accurate to take mid-point values of  x.  We will see geometric reasons for this accuracy, but can experiment directly with sums as follows.  The sum

Sum[  x dx  , {x, a, b-dx, dx}] ~ (b^2 - a^2)/2  when   dx~0
			
We will show this later.  For now, we can compare the two methods:

a = 1; b = 3; dx = 0.1(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx(∑_({{x = a + (dx/2)}, {Δ x = dx}})^(b - (dx/2)))x dx(1/2) ((b^2) - (a^2))

a = 1; b = 3; dx = 0.01(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx(∑_({{x = a + (dx/2)}, {Δ x = dx}})^(b - (dx/2)))x dx(1/2) ((b^2) - (a^2))

Practice Exercises

1)  Compare left summation and mid-point summation of  x dx  for  a = 2 and  b = 3.  What is the exact answer?  What is the error in each method compared with  dx?

a=??
b=??
dx=??
(∑_({{x = a}, {Δ x = dx}})^(b - dx))x dx
(∑_({{x = a + (dx/2)}, {Δ x = dx}})^(b - (dx/2)))x dx
(1/2) ((b^2) - (a^2))

2)  Compare left summation and mid-point summation of  x^2 dx  for  a = 0 and  b = 2.  Can you guess the exact answer? (If so, verify it in several examples of  a  and  b.)  What is the error in each method compared with  dx? (Even if you don't know the exact answer, you can estimate the limit by computing several cases of smaller and smaller  dx.)

a=??
b=??
dx=??
(∑_({{x = a}, {Δ x = dx}})^(b - dx))(x^2) dx
(∑_({{x = a + (dx/2)}, {Δ x = dx}})^(b - (dx/2)))(x^2) dx

Combined Computation of  (∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx

Clear[x, dx]Print["dx    ","\!\(\(\\ \\ \\ ∑\)\+\(\*GridBox[{
{\(x = 0\)},
{\(Δ x = dx\)}
}]\)\%\(1 - dx\)\)x  ≈   ", "   (∑_(({{x = 0}, {Δ x = dx}}))^(1 - dx))x dx ≈   "]Do[ dx = 1/n;
	Print[dx,"      ",(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x ,"≈ ",N[(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x ],"      " ,(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx,"≈ ",N[(∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx ]];
	,{n, 2, 10}];

Exercises

Exercise 12.1.1

The first slicing of the cone in text Example 12.2 gives the following equivalent sum approximations:

(1/2) π (1 + (3^2) + (5^2) + (7^2) + (9^2))(1/2) π (∑_(k = 1)^5)(((2 k - 1))^2)dx = 2; (∑_({{x = (dx/2)}, {Δ x = dx}})^(10 - (dx/2)))π ((((x/2)))^2) dx

Show that the volume approximation for the cone of height 10 and base radius 5 when cut into 10 slices with thickness 1 and radii at the midpoints, 1/2 3/2, ..., 19/2 is
	
	((π )/(4^2)) 
          ((1^2) + (3^2) + (5^2) + ⋯ + (19^2)) = 
        ((π )/8) 665  ≈  261
	
Sum this with Mathematica.

The Volume of a Cone

Use your hand computation from homework to check the next computation, then modify the computation to compute the approximation with up to 2400 terms.  How big is  dx  when there are 2400 terms in the mid-point sum?

Clear[r, x, dx];
r = (x/2);
dx = 2;
(∑_({{x = (dx/2)}, {Δ x = dx}})^(10 - (dx/2)))π (r^2) dxNSum[π (r^2) dx, {x, (dx/2), 10 - (dx/2), dx}]

dx = 1;
(∑_({{x = (dx/2)}, {Δ x = dx}})^(10 - (dx/2)))π (r^2) dxNSum[π (r^2) dx, {x, (dx/2), 10 - (dx/2), dx}]

dx = (1/2);
(∑_({{x = (dx/2)}, {Δ x = dx}})^(10 - (dx/2)))π (r^2) dxNSum[π (r^2) dx, {x, (dx/2), 10 - (dx/2), dx}]

Clear[dx];
(∑_({{x = (dx/2)}, {Δ x = dx}})^(10 - (dx/2)))π (r^2) dx

Exercise 12.4.2

Compare the sums  (∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x   and  (∑_({{x = 0}, {Δ x = dx}})^(1 - dx))x dx  for  dx = 1/2, 1/3, 1/4, ⋯, 1/100 and for  dx = 1/1000.

Exercise C12.4.3

Compare the sums   (∑_({{x = 0}, {Δ x = dx}})^(1 - dx))(x^2) dx  for  dx = 1/2, 1/4, 1/8, ⋯, 1/1024 .