Lesson 5 of 18

Partial Sums of Series

Partial Sums of Series

An infinite series sumansum a_n is defined as the limit of partial sums:

Sn=a1+a2+cdots+an=sumk=1nakS_n = a_1 + a_2 + cdots + a_n = sum_{k=1}^n a_k

If limnoinftySn=Llim_{n o infty} S_n = L, the series converges to LL.

Famous Series

Harmonic series (diverges):

sum rac{1}{k} = 1 + rac{1}{2} + rac{1}{3} + rac{1}{4} + cdots o infty

Basel problem (converges to pi2/6approx1.6449pi^2/6 approx 1.6449):

sum rac{1}{k^2} = 1 + rac{1}{4} + rac{1}{9} + rac{1}{16} + cdots

Telescoping (exact finite sum):

sum_{k=1}^n rac{1}{k(k+1)} = 1 - rac{1}{n+1}

Because rac{1}{k(k+1)} = rac{1}{k} - rac{1}{k+1}, most terms cancel.

Convergence Test: Divergence

If limnoinftyaneq0lim_{n o infty} a_n eq 0, the series must diverge. (But ano0a_n o 0 alone doesn't guarantee convergence — the harmonic series is the classic counterexample.)

Your Task

Implement double partial_sum(double (*a_n)(int), int n) that computes sumk=1nan(k)sum_{k=1}^n a_n(k).

TCC compiler loading...
Loading...
Click "Run" to execute your code.