This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

- Intro to Sage
- Sequences

An infinite series is simply an infinite sum of numbers.

The harmonic series is the sum of the reciprocals of the positive integers:

$1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\cdots+\frac{1}{n}+\cdots$

This may be written with summation notation as $\sum_{n=1}^{\infty}\frac{1}{n}$

The decimal expansion of a real number can be thought of as a series.

$\frac{1}{9}=0.11111\ldots=\frac{1}{10}+\frac{1}{10^2}+\frac{1}{10^3}+\cdots+\frac{1}{10^n}+\cdots=\sum_{n=1}^{\infty}\frac{1}{10^n}$

In this example, we can see that an infinite sum of numbers may give you a finite answer. Such a series is called **convergent**.

Of course, many infinite series do not give you a finite sum. Such series are called **divergent**.

(We'll define these more precisely below.)

One of the easiest ways to get a divergent series is if the terms don't approach zero. That is, $\displaystyle\sum_{n=1}^{\infty}a_n$ diverges if $\displaystyle\lim_{n\to\infty}a_n\ne0$.

On the other hand, if $\displaystyle\lim_{n\to\infty}a_n=0$, this is no guarantee that $\displaystyle\sum_{n=1}^{\infty}a_n$ converges.

Even though $\displaystyle\lim_{n\to\infty}\frac{1}{n}=0$, the harmonic series diverges. This fact was proved as far back as the 14th century by Oresme. His approach was to compare the harmonic series to a series with smaller terms. If the smaller series diverges, then the harmonic series must as well.

Given $1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\cdots+\frac{1}{n}+\cdots$

Replace $1$ with $\frac{1}{2}$, replace $\frac{1}{3}$ with $\frac{1}{4}$, replace each of $\frac{1}{5}$, $\frac{1}{6}$, and $\frac{1}{7}$ with $\frac{1}{8}$, and so on. What you get is the smaller series

$\frac{1}{2}+\frac{1}{2}+\frac{1}{4}+\frac{1}{4}+\frac{1}{8}+\frac{1}{8}+\frac{1}{8}+\frac{1}{8}+\cdots$

$=\frac{1}{2}+\frac{1}{2}+\left(\frac{1}{4}+\frac{1}{4}\right)+\left(\frac{1}{8}+\frac{1}{8}+\frac{1}{8}+\frac{1}{8}\right)+\cdots$

$=\frac{1}{2}+\frac{1}{2}+\frac{1}{2}+\frac{1}{2}+\cdots$

This series diverges, since $\displaystyle\lim_{n\to\infty}\frac{1}{2}=\frac{1}{2}\ne0$.

Compare this result with this convergent series:

$\sum_{n=1}^{\infty}\frac{1}{n^2}=\frac{\pi^2}{6}\approx1.64493406684823$

[Side note: compare this to the improper integrals $\displaystyle\int_1^{\infty}\frac{1}{x}\, dx$ (divergent) and $\displaystyle\int_1^{\infty}\frac{1}{x^2}\, dx$ (convergent). Actually, each series is a Riemann sum for the corresponding integral.]

Given a series $\displaystyle\sum_{n=1}^{\infty}a_n$, we define a *sequence* $\{S_n\}$ as follows:

$S_n=\sum_{i=1}^na_i \quad \mathrm{(add\ up\ the\ first\ n\ terms\ of\ the\ series)}$

$S_n$ is called the nth partial sum of the series.

Find the 10th and 20th partial sums of the series $\displaystyle\sum_{n=1}^{\infty}\frac{2n+1}{3n^2+9}$.

We can use the sum command in Sage, which requires four arguments: sum(expression, index variable, starting value, ending value). Don't forget to declare the index variable first.

Here is the 10th partial sum (I'll convert the answer to a decimal).

28771121/20454564
1.40658686247236

Here is the 20th partial sum.

12139706620041946362/6522879694663705009
1.86109620111088

We define convergence of a series in terms of the sequence of partial sums, $S_n$.

If $\displaystyle\lim_{n\to\infty}S_n$ exists, then we say the series **converges** (or is convergent), and we define the **sum** of the series to be this limit; that is, $\sum_{n=1}^{\infty}a_n=\lim_{n\to\infty}S_n$

If the limit does not exist, then we say the series **diverges** (or is divergent).

Here is a graph of the first 50 partial sums for $\displaystyle\sum_{n=1}^{\infty}\frac{2n+1}{3n^2+9}$.

Notice that the partial sums seem to get bigger and bigger without approaching a limit, which suggests this series diverges.

Sage can handle infinite series. In this case, Sage tells us the series is divergent.

Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/misc/functional.py", line 563, in symbolic_sum
return expression.sum(*args, **kwds)
File "sage/symbolic/expression.pyx", line 11601, in sage.symbolic.expression.Expression.sum (/projects/sage/sage-7.5/src/build/cythonized/sage/symbolic/expression.cpp:63737)
return symbolic_sum(self, *args, **kwds)
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 621, in symbolic_sum
return maxima.sr_sum(expression,v,a,b)
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py", line 892, in sr_sum
raise ValueError("Sum is divergent.")
ValueError: Sum is divergent.

Consider the series $\displaystyle\sum_{n=1}^{\infty}\frac{1}{n}$.

Here is a graph of the first 50 partial sums of this series. It appears the partial sums are getting larger and larger without bound. This is what we expect, since we saw above that this series diverges.

Sage will also tell us that this series diverges.

Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/misc/functional.py", line 563, in symbolic_sum
return expression.sum(*args, **kwds)
File "sage/symbolic/expression.pyx", line 11601, in sage.symbolic.expression.Expression.sum (/projects/sage/sage-7.5/src/build/cythonized/sage/symbolic/expression.cpp:63737)
return symbolic_sum(self, *args, **kwds)
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 621, in symbolic_sum
return maxima.sr_sum(expression,v,a,b)
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py", line 892, in sr_sum
raise ValueError("Sum is divergent.")
ValueError: Sum is divergent.

Consider the series $\displaystyle\sum_{n=1}^{\infty}\frac{1}{n^2}$.

Here is a graph of the first 50 partial sums for this series. Now the partial sums approach a limit around 1.6 (the exact answer is $\frac{\pi^2}{6}\approx1.64493406684823$).

Here is the answer from Sage.

1/6*pi^2

One common type of series is called a geometric series, because the terms form a geometric sequence (a sequence is geometric if the ratio of successive terms is a constant, called the common ratio).

In other words, $\displaystyle\sum_{n=1}^{\infty}a_n$ is a geometric series, if there exists a constant $r$ such that $\displaystyle r=\frac{a_{n+1}}{a_n}$ for all $n\ge1$.

In general, a geometric series has the form $\sum_{n=0}^{\infty}a\cdot r^n=a+a\cdot r+a\cdot r^2+a\cdot r^3+\cdots$

where $a$ is the first term and $r$ is the common ratio (note: it is customary to begin geometric series at $n=0$, although this is not necessary).

Consider the geometric series $\displaystyle\sum_{n=0}^{\infty}\frac{1}{2^n}$. Let's look at the partial sums.

I'll use the sum command in Sage: sum(formula, index variable, start, end)

I'm going to separate out the initial 1 (the 0th term) to make the pattern easier to see.

Interact: please open in CoCalc

As $n\to\infty$, the partial sums approach $2$.

Here is a graph of the sequence of partial sums of the series. It appears the limit of the sequence is 2.

In general, if $-1< r < 1$, then $\displaystyle\sum_{n=0}^{\infty}a\cdot r^n=\frac{a}{1-r}$.

If $r \le -1$ or $r \ge 1$, then this series diverges.

[Note: the index must start at 0 for this formula. You can also think of it as $\displaystyle\frac{\text{first term}}{1-\text{common ratio}}$, and then the index does not matter.]

$\displaystyle\sum_{n=0}^{\infty}\frac{3}{5^n}=\frac{3}{1-\frac{1}{5}}=\frac{15}{4}$ (geometric series with $a=3$ and $r=\frac{1}{5}$)

Here's the answer from Sage.

15/4

$\displaystyle\sum_{n=0}^{\infty}\frac{3^n}{5^n}=\frac{1}{1-\frac{3}{5}}=\frac{5}{2}$ (geometric series with $a=1$ and $r=\frac{3}{5}$)

Here's the answer from Sage.

5/2

Find the sum of the geometric series $\displaystyle \frac{1}{3}+\frac{2}{15}+\frac{4}{75}+\cdots$.

In this case, $a=\frac{1}{3}$ (first term) and $r=\frac{2}{5}$ (common ratio $=\frac{2/15}{1/3}=\frac{4/75}{2/15}$, etc.).

So the sum is $\displaystyle\frac{1/3}{1-2/5}=\frac{5}{9}$.

Here's the answer from Sage.

5/9

5/9

Let's explore the series $\displaystyle\sum_{n=i}^{\infty}a_n$ using Sage.

Try things like $\displaystyle\frac{1}{n},\ \frac{1}{n^2},\ .9^n,\ .99^n,\ .999^n$, etc.

Interact: please open in CoCalc