Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 369
Image: ubuntu2204
Kernel: SageMath 10.1

Sequences

MAT1001 (Calculus I) discussed two key topics in the analysis and computation of functions:

  • derivative of a function,

  • integral of a function.

We are going to talk about a third key topic: infinite series.

Infinite series can be used to

  • express numbers π4=113+1517+19{\pi\over 4} = 1-{1\over 3}+ {1\over 5} -{1\over 7} +{1\over 9} - \cdots

  • express functions cosx=1x22+x44!x66!+x88! \cos x = 1-{x^2\over 2} + {x^4\over 4!} -{x^6\over 6!} +{x^8\over 8!} - \cdots

  • approximate a function using the first few terms

  • represent a function as a polynomial with infinitely many terms (evaluate, differentiate, integrate), e.g., cosx\cos x

Infinite sequences

An infinite sequence, or sequence is a list of numbers {a1,a2,,an,}\{a_1,a_2,\cdots,a_n,\cdots\}

  • A sequence is a function whose domain is the set of integers {1,2,3,}\{1,2,3,\cdots\}, i.e., a1=f(1)a_1=f(1), a2=f(2),.a_2=f(2), \cdots.

  • The integer nn is called the index of ana_n.

  • The index set can start with any integer number other than 1, e.g., {a0,a1,a2,}\{a_0,a_1,a_2,\cdots\}, {b2,b3,b4,}\{b_2,b_3,b_4,\cdots\}, {c2,c1,c0,c1}\{c_{-2},c_{-1},c_0,c_1\cdots\} are sequences.

  • We use {an}n=2\{a_n\}_{n=2}^\infty to denote {a2,a3,a4,}\{a_2,a_3,a_4,\cdots\}. Sometimes, we just say {an}\{a_n\} if the index set is not important or is clear from the context.

Example 1

Consider the sequence 1, 4, 9, 16,25,-1,~4,~-9,~16,-25,\cdots. It can be written in the following ways:

  • an=(1)nn2a_n=(-1)^nn^2 for n1n\geq 1.

  • {(1)nn2}\{(-1)^nn^2\} (n starts at 1 by default)

  • {(1)nn2}n=1\{(-1)^nn^2\}_{n=1}^\infty

  • {(1)n(n2)2}n=3\{(-1)^n(n-2)^2\}_{n=3}^\infty

  • {1, 4, 9, 16,25,}\{-1,~4,~-9,~16,-25,\cdots\}

A sequence can be defined recursively

Fibonacci sequence F0=0, F1=1, Fi=Fi1+Fi2,for i2.F_0=0,~F_1=1,~F_i=F_{i-1}+F_{i-2}, \quad \mbox{for } i\geq 2.

Graphing a sequence

Plot the first 100 terms of the following three sequence.

  • Converges to 00. 1,12,13,14,,1n,1,{1\over2},{1\over3},{1\over4},\cdots,{1\over n},\cdots

  • Diverges because it goes to infinity. 1,2,3,4,,n,1,2,3,4,\cdots,n,\cdots

  • Diverges because it bounces back and forth. 1,1,1,1,,(1)n,1,-1,1,-1,\cdots,(-1)^n,\cdots

n_end = 100 var('n') # Plot the sequence a_n = n, it goes to 0 f(n) = 1/n p1 = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label = r'$%s$'%latex(f)) # Plot the sequence a_n = n, it goes to infinity f(n) = n p2 = point([(n,f(n)) for n in [1..n_end]], size = 30,legend_label = r'$%s$'%latex(f)) # Plot the sequence a_n = (-1)^{n+1}, it bounces between 1 and -1. f(n) = (-1)^(n+1) p3 = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) # Plot the sequence a_n = (1+1/n)^{n}, it goes to e f(n) = (1+1/n)^n p4 = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) graphics_array([p1, p2, p3, p4], 2, 2)
Image in a Jupyter notebook

Since there is no explicit form for the Fibonacci sequence, we define a function to compute the elements in the sequence.

# Fibonacci Sequence a = [0, 1, 1] #add an extra 0 at the beginning, and define the first two terms to be 1, because the index starts at 0 in SageMath n_end = 10 for n in [3..n_end]: #note: the next line needs to be indented a += [a[n-1]+a[n-2]] #add the next term to the list (notice the square brackets around the thing you're adding) point([(n,a[n]) for n in [1..n_end]], size = 30, legend_label='Fibonacci sequence') #once the list is done, plot the points
Image in a Jupyter notebook

Convergence

A sequence {an}\{a_n\} converges to the number LL if for any positive number ϵ\epsilon, there exists an integer NN such that for all n>Nn>N, anL<ϵ.|a_n - L|<\epsilon.

If {an}\{a_n\} converges to LL, we write limnan=L\lim\limits_{n\rightarrow\infty} a_n = L, or simply anLa_n\rightarrow L, and call LL the limit of the sequence {an}\{a_n \}.

  • NN depends on ϵ\epsilon, in general, a smaller ϵ\epsilon requires a bigger NN.

  • n>Nn>N can be replaced by nNn\geq N.

  • If no such number LL exists, we say that {an}\{a_n\} diverges.

# Plot the sequence n_end = 100 var('n') f(n) = (1+1/n)^n g = points([(n, (1+1/n)^n) for n in [5..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) limit = e epsilon = float(0.02) # plot the limit line g += line([(0, limit), (n_end, limit)], color='black', legend_label=r'$y=e$') # Plot the limit neighborhood for y, color in zip([epsilon, 2*epsilon], ['red', 'green']): g += plot([limit-y, limit+y], 0, n_end, fill={1: [0]}, fillcolor = color, color = color, fillalpha = 0.5, legend_label=r'$\epsilon=%s$'%latex(y)) g.show()
Image in a Jupyter notebook

Examples

  • For the case an=1n.a_n={1\over n}. We know that it converges to 00, so L=0L=0. We need to have an0<ϵ,|a_n-0|<\epsilon, which is the same as n>1ϵn>{1\over \epsilon}. We we need to choose the integer N>1ϵ.N>{1\over \epsilon}.

  • For the case n2n+1{n\over 2n+1} We know that it converges to 12{1\over 2}, so L=12L={1\over 2}. We need to have an12=12(2n+1)<ϵ,\left|a_n-{1\over 2}\right|={1\over 2(2n+1)}<\epsilon, which is the same as n>12(12ϵ1).n>{1\over2}\left({1\over 2\epsilon}-1\right).

  • For the case (1)n(-1)^n If LL exists, then we have L(1ϵ,1+ϵ)L\in (1-\epsilon, 1+\epsilon) and L(1ϵ,1+ϵ)L\in (-1-\epsilon, -1+\epsilon) for a small ϵ\epsilon, which can not happen. So LL does not exist.

Divergence to infinity

  • limnan=, or an\lim\limits_{n\rightarrow\infty}a_n=\infty, \mbox{ or } a_n\rightarrow \infty

If for every MRM\in R, there exists NN such that an>Ma_n>M for all n>Nn>N. We say that {an}\{a_n\} diverges to \infty

  • limnan=, or an\lim\limits_{n\rightarrow\infty}a_n=-\infty, \mbox{ or } a_n\rightarrow -\infty

If for every MRM\in R, there exists NN such that an>Ma_n>M for all n>Nn>N. We say that {an}\{a_n\} diverges to -\infty

Summary: Possible outcomes

  • Convergence

  • Divergence

    • Divergence to \infty or -\infty.

    • Other divergence cases {1,2,3,4,}\{1,-2,3,-4,\cdots\} {1,0,2,0,3,0,}\{1,0,2,0,3,0,\cdots\}

Remarks: The first finitely many terms do not change the convergence

Adding/removing/changing finitely many terms to a sequence does not change its convergence/divergence.

  • {7,48,56,π,12,13,14,}\{7, 48, 56, -\pi, {1\over 2}, {1\over 3}, {1\over 4}, \cdots\}
  • {46,3,e1,1,1,1,1,1,}\{46, 3, e^{-1}, -1, 1, -1, 1, -1,\cdots\}

Calculating limits of sequences

Similar to the theorems on limits of functions in Chapter 2, we have the following theorem.

Let {an}\{a_n\} and {bn}\{b_n\} be convergent sequences of real numbers with anAa_n\rightarrow A and bnBb_n\rightarrow B.

  • Sum Rule: limn(an+bn)=A+B\lim\limits_{n\rightarrow\infty}(a_n+b_n)=A+B

  • Difference Rule: limn(anbn)=AB\lim\limits_{n\rightarrow\infty}(a_n-b_n)=A-B

  • Constant Multiple Rule: limn(kbn)=kB\lim\limits_{n\rightarrow\infty}(k\cdot b_n)=k\cdot B (any real number kk)

  • Product Rule: limn(anbn)=AB\lim\limits_{n\rightarrow\infty}(a_n\cdot b_n)=A\cdot B

  • Qutient Rule: limnanbn=AB\lim\limits_{n\rightarrow\infty}{a_n\over b_n}={A\over B}\quad if B0B\neq 0

Example

limnn2+1n3+3\lim\limits_{n\rightarrow\infty}{n^2+1\over n^3+3}

Note that n2+1n3+3=1n+1n31+3n3.{n^2+1\over n^3+3}={\displaystyle{1\over n}+{1\over n^3}\over \displaystyle 1+{3\over n^3}}. So limnn2+1n3+3=0+01+0=0.\lim\limits_{n\rightarrow\infty}{n^2+1\over n^3+3}={0+0\over 1+0}=0.

#Since we used the letter n above, we need to declare it as a variable now. var('n') f(n) = (1+1/n)^n print('The limit of', f(n), ' is', limit(f(n), n=+Infinity)) f(n) = (n^2 + 1)/(n^3 + 3) print('The limit of', f(n), ' is', limit(f(n), n=+Infinity))
The limit of (1/n + 1)^n is e The limit of (n^2 + 1)/(n^3 + 3) is 0

Remark

  • It can happen that limn(an+bn)\lim\limits_{n\rightarrow\infty}(a_n+b_n) exists but both limnan\lim\limits_{n\rightarrow\infty}a_n and limnbn\lim\limits_{n\rightarrow\infty}b_n do not exist.

    • Example: an=n+1,bn=1na_n = n + 1,\qquad b_n= 1-n

  • {an}\{a_n\} and {can}\{ca_n\} (c0c\neq 0) are divergent or convergent at the same time.

Note: Limit treats the sequence as a function.

In the following example, the limit returns "ind", which means "indefinite but bounded." However, the sequence sin(πn)\sin (\pi n) has a limit 0, but the function sin(πx)\sin(\pi x) oscillates between 1 and -1 forever.

Instead, we can have the assumption that nn is integer by assume(n, 'integer')

reset() var('n') f(n) = sin(pi*n) print('The limit of', f(n), 'in Sagemath is', limit(f(n), n=+Infinity), ' because it treats the sequence as a function.') assume(n, 'integer') print('We need to restrict n to be integer, and the limit of', f(n), 'becomes', limit(f(n), n=+Infinity))
The limit of sin(pi*n) in Sagemath is ind because it treats the sequence as a function. We need to restrict n to be integer, and the limit of sin(pi*n) becomes 0
# plot the function $sin(x*pi)$ and the sequence $sin(n*pi)$ n_end = 25 f(n) = sin(pi*n) g = point([(n, f(n)) for n in [2..n_end]], size = 30, legend_label='sequence '+r'$%s$'%latex(f)) f = sin(pi*x) g += plot(f, xmin=1, xmax=n_end, color='red', legend_label = 'function '+r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook

Sandwich theorem for sequences

Let {an} ,{bn},\{a_n\}~,\{b_n\}, and {cn}\{c_n\} be sequences of real numbers. If anbncna_n\leq b_n\leq c_n holds for all nNn\geq N, and if limnan=limncn=L\lim\limits_{n\rightarrow\infty}a_n=\lim\limits_{n\rightarrow\infty}c_n=L, then limnbn=L\lim\limits_{n\rightarrow\infty}b_n=L.

  • limnn!nn\lim\limits_{n\rightarrow\infty}{n!\over n^n}

n_end = 16 var('n') f(n) = factorial(n)/n^n g = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = 2/n^2 g += point([(n,f(n)) for n in [1..n_end]], color = 'red', legend_label=r'$%s$'%latex(f)) f(n) = 0 g += point([(n,f(n)) for n in [1..n_end]], color = 'cyan', legend_label=r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook

If limnan=0\lim\limits_{n\rightarrow\infty}|a_n|=0, then limnan=0\lim\limits_{n\rightarrow\infty}a_n=0

limn(1)n1n\lim\limits_{n\rightarrow\infty}(-1)^n{1\over n}
n_end = 100 var('n') f(n) = (-1)^n/n g = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = 1/n g += point([(n,f(n)) for n in [1..n_end]], color = 'red', legend_label=r'$%s$'%latex(f)) f(n) = -1/n g += point([(n,f(n)) for n in [1..n_end]], color = 'cyan', legend_label=r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook

Continuous function theorem for sequences

Let {an}\{a_n\} be a sequence with anLa_n\rightarrow L and ff is a function that is continuous at LL and defined at all {an}\{a_n\}, then f(an)f(L)f(a_n)\rightarrow f(L).

  • Example: limn21n\lim\limits_{n\rightarrow\infty} 2^{1\over n}

limn21n=2limn1n=20=1\lim\limits_{n\rightarrow\infty} 2^{1\over n}= 2^{\lim\limits_{n\rightarrow\infty} {1\over n}} = 2^0 = 1

Using l'Hopital's rule

Support that f(x)f(x) is a function defined for all xn0x\geq n_0 and that {an}\{a_n\} is a sequence such that an=f(n)a_n=f(n) for all nn0n\geq n_0. Then limxf(x)=Llimnan=L.\lim\limits_{x\rightarrow\infty}f(x)=L\Longrightarrow\lim\limits_{n\rightarrow\infty}a_n=L.

  • Example: limnlnnn\lim\limits_{n\rightarrow\infty}{\ln n\over n}

When nn\rightarrow \infty, we have limnlnnn=limn1n1=0\lim\limits_{n\rightarrow\infty}{\ln n\over n}=\lim\limits_{n\rightarrow\infty}{{1\over n}\over 1}=0

n_end = 100 var('n') f(n) = log(n)/n g = point([(n,f(n)) for n in [1..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook

limn(n+1n1)n\lim\limits_{n\rightarrow\infty}{\left({n+1\over n-1}\right)^n}

If we take the limit, we get 11^\infty, which is undeterminated.

We can take the log first, we have

limnnlog(n+1n1)=limnlog(1+2n1)1n=limnn1n+1(2(n1)2)1n2=2.\lim\limits_{n\rightarrow\infty}n\log {\left({n+1\over n-1}\right)}=\lim\limits_{n\rightarrow\infty}{\log {\left(1+{2\over n-1}\right)}\over {1\over n}}=\lim\limits_{n\rightarrow\infty}{{n-1\over n+1}(-{2\over (n-1)^2})\over -{1\over n^2}}=2.

Therefore, limn(n+1n1)n=e2\lim\limits_{n\rightarrow\infty}{\left({n+1\over n-1}\right)^n}=e^2

n_end = 100 var('n') f(n) = ((n+1)/(n-1))^n g = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook

Find the limit of a recursively defined sequence

When we are given a recursively defined sequence, we can first look at the graph to see if the limit exists or not. Then we calculate many values of the sequence and see where we end up.

Example

If {an}\{a_n\} is the Fibonacci sequence, which does not converge, what about the sequence bn=an+1an.b_n={a_{n+1}\over a_n}.

We can take a look at the graph first.

n_end = 20 a=[0, 1, 1] #First, define the Fibonacci Sequence for n in [3..n_end+1]: a+=[a[n-1]+a[n-2]] b=[0] for n in [1..n_end]: #Now define the new sequence b+=[a[n+1]/a[n]] point([(n,b[n]) for n in [1..n_end]], size=30)
Image in a Jupyter notebook

The limit of the sequence is the "Golden Ratio" 1+52.{1+\sqrt{5}\over 2}.

Common limits (xx is fixed)

  • limnlnnn=0\lim\limits_{n\rightarrow\infty}{\ln n\over n}=0
  • limnnn=1\lim\limits_{n\rightarrow\infty}\sqrt[n]{n}=1
  • limnx1n=1(x>0)\lim\limits_{n\rightarrow\infty}x^{1\over n}=1 \qquad (x>0)
  • limnxn=0(x<1)\lim\limits_{n\rightarrow\infty}x^n =0\qquad (|x|<1)
  • limn(1+xn)n=ex(any x)\lim\limits_{n\rightarrow\infty}\left(1+{x\over n}\right)^n=e^x \qquad (\text{any }x)
  • limnxnn!=0(any x)\lim\limits_{n\rightarrow\infty}{x^n\over n!}=0\qquad (\mbox{any }x)
n_end1 = 1000 f(n) = log(n)/n p1 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = n^(1/n) p2 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = 5^(1/n) p3 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = float(0.5)^n p4 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = (1+1/n)^n p5 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) f(n) = 5^n/factorial(n) p6 = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) graphics_array([p1, p2, p3, p4, p5, p6], 2, 3)
Image in a Jupyter notebook

Bounded sequences

A sequence {an}\{a_n\} is bounded from above if there exists a number MM such that anMa_n\leq M for all nn. The number M is an upper bound for {an}\{a_n\}. If MM is an upper bound for {an}\{a_n\} but no number less than MM is an upper bound for {an}\{a_n\}, then MM is the least upper bound for {an}\{a_n\}.

A sequence {an}\{a_n\} is bounded from below if there exists a number mm such that anma_n\geq m for all nn. The number mm is a lower bound for {an}\{a_n\}. If mm is a lower bound for {an}\{a_n\} but no number greater than mm is a lower bound for {an}\{a_n\}, then mm is the greatest lower bound for {an}\{a_n\}.

If {an}\{a_n\} is bounded from above and below, then {an}\{a_n\} is bounded. If {an}\{a_n\} is not bounded, then we say that {an}\{a_n\} is an unbounded sequence.

  • {n}\{n\}

  • {nn+1}\{{n\over n+1}\}

Bounded monotonic sequences

A sequence {an}\{a_n\} is nondecreasing if anan+1a_n\leq a_{n+1} for all nn. That is, a1a2a3a_1\leq a_2\leq a_3\leq\cdots. The sequence is nonincreasing if anan+1a_n\geq a_{n+1} for all nn. The sequence {an}\{a_n\} is monotonic if it is either nondecreasing or nonincreasing.

  • {3}\{3\} is bounded monotonic

  • (1)n{(-1)^n} is bounded but not monotonic

  • {nn+1}\{{n\over n+1}\} is bounded and monotonic

A bounded and monotonic sequence converges.

Code for ploting a sequence and find the limit of a sequence

n_end = 100 var('n') f(n) = ((n+1)/(n-1))^n g = point([(n,f(n)) for n in [2..n_end]], size = 30, legend_label=r'$%s$'%latex(f)) g.show()
Image in a Jupyter notebook
reset() var('n') #assume(n, 'integer') f(n) = ((n+1)/(n-1))^n print('The limit of', f(n),'is', limit(f(n), n=+Infinity))
The limit of ((n + 1)/(n - 1))^n is e^2