Lab 8: Sequences and Series

MAT 229, Spring 2025

How do we visualize sequences and compute limits in Mathematica? It’s easy! 

They behave a lot like functions -- in fact, they are functions -- on the domain of the natural numbers (or some other subset of the integers).

Our key commands this week include 
	Sum
	Table and TableForm
	ListPlot (options: PlotRange -> All)
	Limit 
	Rest and Most
	Solve
	NewtonsMethod[f,x0,eps,nits] (our work from the previous lab, Lab 7)

Exercises

Exercise 1: defining and visualizing sequences and partial sums

Consider the sequence given by the formula (Subscript[{(Subscript[a, k])}, k=1]^∞)= (Subscript[{((((k!))^2)/((2k)!))}, k=1]^∞).  (The parentheses are important here. Make sure you have them in the correct places. And you might want an extra pair....)

a[k_]:=(k!)^2/((2k)!)

Plot the first 20 terms of this sequence. From this plot, what do you think is the value of (lim_(k->∞))((((k!))^2)/((2k)!))?

ListPlot[Table[{k,a[k]},{k,1,20}],PlotRange->All]

Plot the first 20 partial sums (Subscript[S, n])=(Underoverscript[Σ, (k=1), n])((((k!))^2)/((2k)!)) . Based on this plot, do you think the series (Underoverscript[Σ, (k=1), ∞])((((k!))^2)/((2k)!)) converges or not. If you think it converges, estimate its value.

s[n_]:=Sum[a[k],{k,1,n}]
ListPlot[Table[{k,s[k]},{k,1,20}],PlotRange->All]
Limit[1/k,k->Infinity]

Exercise 2: the harmonic and alternating harmonic series

Consider the harmonic series (Underoverscript[Σ, (k=1), ∞])(1/k) and the alternating harmonic series (((Underoverscript[Σ, (k=1), ∞])(-1))^(k+1))(1/k).

hs[k_]:=1.0/k

The harmonic series (Underoverscript[Σ, (k=1), ∞])(1/k) diverges.

Compute the partial sums for this series as decimal values:
	(Subscript[S, 10]),(Subscript[S, 100]),(Subscript[S, 1000]),(Subscript[S, 10000]),(Subscript[S, 100000]),(Subscript[S, 1000000]).

s[n_]:=Sum[hs[k],{k,1,n}]
sums=TableForm[Table[{10^k,s[10^k]},{k,1,6}]]
ListPlot[Table[{k,s[k]},{k,1,100}],PlotRange->All]

Estimate by how much the partial sums go up when we increase the number of terms in the partial sum by a factor of 10.

Rest[sums]-Most[sums]

The alternating harmonic series (Underoverscript[Σ, (k=1), ∞])((((-1))^(k+1))/k) converges.

ahs[k_]:=(-1.0)^(k+1)/k

Compute the partial sums for this series as decimal values:
	(Subscript[S, 10]),(Subscript[S, 100]),(Subscript[S, 1000]),(Subscript[S, 10000]),(Subscript[S, 100000]),(Subscript[S, 1000000]).

s[n_]:=Sum[ahs[k],{k,1,n}]
sums=Table[{10^k,s[10^k]},{k,1,6}]
ListPlot[Table[{k,s[k]},{k,1,100}],PlotRange->All]
Log[2.0]

To 4 decimal places, what does the alternating harmonic series converge to?

sums
Limit[s[k],k->Infinity]

Exercise 3: geometric series

Geometric series have the form (Underoverscript[Σ, (k=0), ∞])a (r^k). It converges if and only if |r|<1. If it does converge it converges to (a/(1-r)). The  (n^th) partial sum is given by  a((1-(r^n))/(1-r)).

Thus the absolute error in the (n^th) partial sum (providing the series converges) is given by  a((r^n)/(1-r)).

The geometric series (Underoverscript[Σ, (k=0), ∞]) (((0.5))^k) converges to (1/(1-0.5))=2. Create a plot of the partial sums of this series. Use it to help you zero in on the first partial sum that is within 0.001 of the series value.

gs[k_]:=(0.5)^k

Plot the partial sums as points until you see where they level off.

s[n_]:=Sum[gs[k],{k,0,n}]
sums=Table[{k,2-s[k]},{k,1,20}]
ListPlot[Table[{k,s[k]},{k,1,20}],PlotRange->All]

Use whatever means you have, graphical or analytical, to determine where the partial sums start getting within 0.0001 of the convergent value.

absError[r_,n_]:=r^n/(1-r)
TableForm[Table[{k,absError[0.5,k]},{k,1,20}]]
ListPlot[Table[{k,absError[0.5,k]},{k,1,20}],PlotRange->All]

Solve[s[n]==1.999,n]

Use Newton’s method to approximate where the partial sums start getting within 0.0001 of the limiting value.

f[x_]:=s[x]-1.999
NewtonsMethod[f,5,eps,nits]

The geometric series (Underoverscript[Σ, (k=0), ∞]) (((0.95))^k) converges to (1/(1-0.95))=20. Determine the first partial sum that is within 0.0001 of the series value.

gs[k_]:=(0.95)^k

Plot the partial sums as points until you see where they level off.

s[n_]:=Sum[gs[k],{k,0,n}]
sums=Table[{k,20-s[k]},{k,1,20}]
ListPlot[Table[{k,s[k]},{k,1,100}],PlotRange->All]

Use whatever means you have to determine where the partial sums start getting within 0.0001 of the convergent value.

Solve[s[n]==19.9999,n]
f[x_]:=s[x]-19.9999
NewtonsMethod[f,5,0.00001,20]

Exercise 4: another sort of “alternating series”, and a warning.

Let the sequence (Subscript[{(Subscript[a, k])}, k=1]^∞) be given by  (Subscript[{(((-1))^(k(k+1)/2))((k!)/(10^k))}, k=1]^∞).

a[k_]:=(-1)^(k(k+1)/2)(k!)/(10^k)

Create a list of the first 10 terms of this sequence.

s[n_]:=Sum[a[k],{k,1,n}]
firstTerms=Table[{k,a[k]},{k,1,10}]
ListPlot[firstTerms,PlotRange->All]

What is the pattern with the signs?

Do you have a guess on what is the value of (lim_(k->∞))(Subscript[a, k])?

Create a list of the first 20 terms of this sequence.

What is the pattern with the signs?

firstTerms=Table[{k,a[k]},{k,1,20}]
ListPlot[firstTerms,PlotRange->All]

Do you have a guess on what is the value of (lim_(k->∞))(Subscript[a, k])?

Create a list of the first 30 terms of this sequence.

What is the pattern with the signs?

firstTerms=Table[{k,a[k]},{k,1,30}]
ListPlot[firstTerms,PlotRange->All]

Do you have a guess on what is the value of (lim_(k->∞))(Subscript[a, k])?

What is true about (Underoverscript[Σ, (k=1), ∞])(Subscript[a, k])? Give reasons for your answer.