Project 12: Sum of Finite Geometric Series

Suppose we drop a basketball from 200 feet.  Every time the ball bounces, it reaches a height .6 times the previous height.

The sequence of heights looks like:

200, 120, 72, 43.2, 25.92,...

What is the total distance traveled by the ball when it touches the ground the fourth time?

Drop from 200 feet = 200 feet total

Bounce up 120 feet = 320 feet total

Fall from 120 feet = 440 feet total

Bounce up 72 feet = 512 feet total

Fall from 72 feet = 584 feet total

If we were only concerned the distance the ball traveled upwards, we could look at the sequence:

120, 72, 43.2, 25.92, 15.552...

After the fifth bounce, the ball bounces to a height of 15.552

What is the total distance traveled by the ball upwards when it reaches the height of 15.552?

275.672 feet.

Consider the following geometric sequence:

2, 10, 50, 250, 1250, 6250, ...

The series (sum of the first n terms of a sequence) with n = 4 would be 2 + 10 + 50 + 250 or 312.

In the project below, try to use a loop to add consecutive terms of the sequence.  In the course, we also derive the formula for a finite geometric series as shown below (we have called r 'rat'; both stand for ratio).

You can also implement the code for this formula, but first try using a loop (for or while loop)

 Second Ball Bouncing Example using the formula:

Sum = 120((1  -.6^5)/(1-.6) = 275.672 feet.

Project 12: Variables 'firstVal', 'rat', and 'n' have been initialized.  

firstVal represents the first value in the geometric sequence (2 in the example given)

rat represents the common ratio of the geometric sequence (5 in the example given)

n represents the number of terms in the series (sum of first n terms) (4 in the example given)

Task: Appropriately initialize the variable 'value' that represents the sum of the first 'n' terms of the geometric sequence.

**If your code works for 5 test cases in a row, you can enter your e-mail address.

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0