Adding Up Sequences

  Download Java Source Code

/*** Adding Up Sequences **********************************
Moe's math class is investigating adding up number sequences.
For example: 1/2 + 1/4 + 1/8 + ... = 1
They tried to find a formula for:  1/2 + 1/3 + 1/4 + ...
The teacher claimed that this sequence can grow infinitely big.
The following program will add up the sequence, stopping at 2.0
***********************************************************/

Math Sequences and Computational Methods

Mathematicians study sequences of numbers.  A sequence is a list of numbers that follows a pattern.
Common examples are Arithmetic Sequences (adding the same number over and over)

     1 , 3 , 5 , 7 , 9  (always adding 2)
     Total = 5/2(1+9) = 25

and Geometric Sequences (multiplying by the same number over and over).

     1 , 2 , 4 , 8 , 16 , 32  (always multiplying by 2)
     Total = 2^6 - 1

Arithmetic and Geometric sequences are well understood by mathematicians.
They have simple formulas for adding up a lot of terms of the sequence.

This program adds up a sequence that is neither  arithmetic nor geometric.  It adds up these fractions:

     1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 + 1/10 + 1/11
     Total = approximately 2.02, but there is no exact formula

A non-standard sequence like this does not have a nice simple formula for adding it up.
The best way to get a result is to use a computational method - that is, a computer program
that follows rules and calculates the total by normal calculations. 

Computational methods are not perfectly accurate, because computers do not do perfect calculations.
Computers must round-off or truncate results so that they can be stored in memory.
The tiny errors are unacceptable to mathematicians, but scientists and engineers are satisfied with approximate answers.
Although computation produces slight inaccuracies, they have the advantage that complex rules
can be programmed reasonably easily, so some useful results can be obtained without difficult mathematics.
Even if there is an exact mathematical formula, it is often easier to write a computer program.

Practice