A series is the sum of the terms in a sequence. For some sequences, the more terms are added, the closer the sum gets to some finite number. Such series are set to converge.
Below, you can approximate the sum of an infinite sequence by computing Σ(n=0, N)f(n) for some large N.
Some convergent series to try
Series | JavaScript | Converges to |
---|---|---|
Geometric series (r=1/2) | 1 / Math.pow(2, n) |
2 |
Geometric series (r=1/3) | 1 / Math.pow(3, n) |
1.5 |
1/n² series | 1 / Math.pow(n + 1, 2) |
π²/6 ≈ 1.645 |
1/n! series | 1 / factorial(n) |
e ≈ 2.718 |
Alternating series | Math.pow(-1, n) / (n + 1) |
ln(2) ≈ 0.693 |
Note: For the factorial function, you'll need to define it first:
function factorial(n) { return n <= 1 ? 1 : n * factorial(n-1); }