Calculus II: The Relation between Sequences and Series

Barry McQuarrie
Oct 2012
Graphical relation between a sequence and the series created from the sequence.

Example 1: Using Mathematica to Investigate a Geometric Series

Here is how we can define a sequence (Subscript[a, i])=1/(2^i), and the sequence of partial sums (Subscript[s, n])=(∑_(i=1)^n)(Subscript[a, i]) in Mathematica:

a[i_]:=1/2^i
s[n_]:=Sum[a[i],{i,1,n}]

We use the set delayed :=so that if we make changes to the sequence we don’t have to re-evaluate everything (it just prevents possible errors down the road). We can get a look at the sequence and teh sequence of partial sums by using the Table command:

sequence=Table[{i,a[i]},{i,1,30}]
sequencepartialsum=Table[{i,s[i]},{i,1,30}]

If we want decimal output we can use the N command. Notice since i is an integer I only get decimals approximation for (Subscript[a, i]) and (Subscript[s, i]).

sequence=Table[{i,N[a[i],10]},{i,1,30}]
sequencepartialsum=Table[{i,N[s[i],10]},{i,1,30}]

If you like, you can present the data in a table using the TableForm command:

TableForm[sequence]

TableForm[sequencepartialsum]

From the decimal output, we can guess that the limit of the sequence is 0, and the limit of the sequence of partial sums is 1. You could also use the ListPlot command to guess this:

ListPlot[{sequence,sequencepartialsum},PlotStyle->{{Blue,PointSize[0.02]},{Red,PointSize[0.02]}}]

The original sequence (blue dots) converges to zero, and the sequence of partial sums formed from the sequence (red dots) converges to 1. The command Limit can verify this for you. Notice we have to tell Mathematica that n is an integer.

Limit[a[n],n->Infinity,Assumptions->Element[n,Integers]]
Limit[s[n],n->Infinity,Assumptions->Element[n,Integers]]

Example 2: Harmonic Series

Here is the Harmonic series, where (Subscript[a, i])=1/i

a[i_]:=1/i
s[n_]:=Sum[a[i],{i,1,n}]

sequence=Table[{i,N[a[i],10]},{i,1,30}]
sequencepartialsum=Table[{i,N[s[i],10]},{i,1,30}]

ListPlot[{sequence,sequencepartialsum},PlotStyle->{{Blue,PointSize[0.02]},{Red,PointSize[0.02]}}]

The original sequence (blue dots) converges to zero, and the sequence of partial sums formed from the sequence (red dots) diverges.

Limit[a[n],n->Infinity,Assumptions->Element[n,Integers]]
Limit[s[n],n->Infinity,Assumptions->Element[n,Integers]]

Example 3

a[i_]:=Cos[2Pi*i]
s[n_]:=Sum[a[i],{i,1,n}]

sequence=Table[{i,N[a[i],10]},{i,1,30}]
sequencepartialsum=Table[{i,N[s[i],10]},{i,1,30}]

ListPlot[{sequence,sequencepartialsum},PlotStyle->{{Blue,PointSize[0.02]},{Red,PointSize[0.02]}}]

The original sequence (blue dots) converges to 1, and the sequence of partial sums formed from the sequence (red dots) diverges.

Limit[a[n],n->Infinity,Assumptions->Element[n,Integers]]
Limit[s[n],n->Infinity,Assumptions->Element[n,Integers]]

Notice this is a place where Mathematica would get the limit wrong if we don’t tell it n is an integer:

Limit[a[n],n->Infinity]

Example 4: Worked by Hand in Class (telescoping and geometric series)

a[i_]:=3/i/(i+3)+5/4^i
s[n_]:=Sum[a[i],{i,1,n}]

sequence=Table[{i,N[a[i],10]},{i,1,30}]
sequencepartialsum=Table[{i,N[s[i],10]},{i,1,30}]

ListPlot[{sequence,sequencepartialsum},PlotStyle->{{Blue,PointSize[0.02]},{Red,PointSize[0.02]}}]

The original sequence (blue dots) converges to zero, and the sequence of partial sums formed from the sequence (red dots) appears to be converging, but it is hard to tell from the graph what it convereges to.

Limit[a[n],n->Infinity,Assumptions->Element[n,Integers]]
Limit[s[n],n->Infinity,Assumptions->Element[n,Integers]]

Example 5

a[i_]:=1/(Sqrt[i!])
s[n_]:=Sum[a[i],{i,1,n}]

sequence=Table[{i,N[a[i],10]},{i,1,30}]
sequencepartialsum=Table[{i,N[s[i],10]},{i,1,30}]

ListPlot[{sequence,sequencepartialsum},PlotStyle->{{Blue,PointSize[0.02]},{Red,PointSize[0.02]}}]

The original sequence (blue dots) converges to zero, and the sequence of partial sums formed from the sequence (red dots) appears to be converging, but it is hard to tell from the graph what it convereges to. Mathematica can't figure it out for us.

Limit[a[n],n->Infinity,Assumptions->Element[n,Integers]]
Limit[s[n],n->Infinity,Assumptions->Element[n,Integers]]

Example 6: A Sequence Defined Recursively: the Fibonacci Sequence

We have to be careful when we set up recursive sequences in Mathematica. Here is how you can do it effectively, for the sequence given by

a[1]=1;
a[2]=1;
a[n_]:=a[n]=a[n-1]+a[n-2]

sequence=Table[{i,a[i]},{i,1,10}];
TableForm[sequence]

The first two lines define the initialization, and so can be direct assignments. 
The last time may look weird, but it is a delayed assignment with the a[n_]:= and then the a[n]= stores the assignment so it doesn’t have to be computed again. This speeds up the code significantly if n is large, as the following computation shows.

a[1]=1;
a[2]=1;
a[n_]:=a[n]=a[n-1]+a[n-2]

b[1]=1;
b[2]=1;
b[n_]:=b[n-1]+b[n-2]

Timing shows the time it took to compute, and the result:

Timing[a[32]]
Timing[b[32]]

If we select the first component we can just get the time:

Timing[b[32]][[1]]

Here is a plot of the time it took for a the first items in the sequence:

ListPlot[Table[{i,Timing[a[i]][[1]]},{i,1,34}],PlotStyle->{Red,PointSize[0.02]},AxesLabel->{"i","Time"}]

ListPlot[Table[{i,Timing[b[i]][[1]]},{i,1,34}],PlotStyle->{Red,PointSize[0.02]},AxesLabel->{"i","Time"},PlotRange->{All,All}]

As you can see, the time will soon become a real issue in implementing our recursion relation unless we store the intermediate results.