Lesson 6 of 18

Geometric Series

Geometric Series

A geometric series has each term a constant multiple of the previous:

sumk=0n1acdotrk=a+ar+ar2+cdots+arn1sum_{k=0}^{n-1} a cdot r^k = a + ar + ar^2 + cdots + ar^{n-1}

Closed-Form Formula

For req1r eq 1:

S_n = a cdot rac{1 - r^n}{1 - r}

Convergence

The infinite geometric series sumacdotrksum a cdot r^k converges if and only if r<1|r| < 1:

sum_{k=0}^{infty} a cdot r^k = rac{a}{1 - r} quad ext{when } |r| < 1

rrSeries behavior
r=0.5r = 0.5converges to 2a2a
r=1r = 1diverges (grows linearly)
r=2r = 2diverges (grows exponentially)
r=1r = -1oscillates (diverges)

Example

a=1a = 1, r=0.5r = 0.5, n=10n = 10:

ight) approx 1.9980$$ The infinite sum: $ rac{1}{1-0.5} = 2$ — the partial sum already reached $1.998$. ### Your Task Implement `double geometric_partial(double a, double r, int n)` that computes $sum_{k=0}^{n-1} a cdot r^k$ using a loop.
TCC compiler loading...
Loading...
Click "Run" to execute your code.