Sequences

Creating a Sequence

In mathematica, sequences are represented as Lists. To create a list, use commas to seperate individual elements and braces at the begining and end. For example, the sequence (Subscript[{ (n^2) }, n=1]^10) can be written out as...

A = {1,4,9,16,25,36,49,64,81,100}

To access the (4^th) element of the sequence A double bracket are used.

A[[4]]

It is often more convient to create a sequence using the definition. For an explicit definitions, like (Subscript[a, n])= (n^2), the Mathematica function Table[] will generate a list over a range of i values.

A = Table[n^2,{n,1,1000}];

A[[11]]

A[[768]]

For sequences that are defined recursively the Mathematica function RecurrenceTable[] takes in a list of equations defining the sequence, the name of the variable to put in each element of the list, and a . For example, a geometric series with common ration 3 and first term (Subscript[a, 1])= 2 has the recursive definition (Subscript[a, n])= 3 (Subscript[a, n-1]). To create this sequence from the recursive definition, the proper code is...

Geo = RecurrenceTable[{a[1]==2,a[n]==(3)a[n-1]},a,{n,1,8}]

Another example could be the Fibonacci Sequence, defined as (Subscript[a, 1])=1, (Subscript[a, 2])=1 and (Subscript[a, n])= (Subscript[a, n-1])+(Subscript[a, n-2])

Fib = RecurrenceTable[{a[1]==1,a[2]==1,a[n]==a[n-1]+a[n-2]},
a,{n,1,10}]

Most famous sequences also have their own dedicated function. The (10^th) term of the fibonacci sequence can also be fond using Fibonacci[].

Fib[[10]]

Fibonacci[10]

To find the sum of the terms in a sequence (in other words a series, which we will be taking about exensively) use the function Sum[].

Sum[Fib[[n]],{n,1,10}]

Plotting a Sequence

Suppose we come across a new and strange sequence.

(Subscript[a, n])= ((cos(2n))/n)

This sequence has an explicit definition, so Table[] will be able to create the sequence.

A = Table[((Cos[2.0n])/n),{n,1,10}]

This is a little hard to parse. A more visually pleasing version of the sequence A  can be created using MatrixForm[].

MatrixForm[A]

To build some intuition about this sequence, the ListPlot[] function can plot a sequence of numbers. Remember that in Mathematica sequences are stored as Lists. Like many Mathematica functions, ListPlot[] has a number of different uses. For now, giving just a sequence of numbers as the input produces exactly what we want.

ListPlot[A]

As n increases, the terms of the sequnce bounce around alot, but there is an over all trend torwards zere. Taking a few more terms of the sequence can verify this.

A = Table[((Cos[2n])/n),{n,1,60}];

SeqPlot =ListPlot[A,PlotRange->{-0.5 ,0.4}]

Infinite Sequences

Explicit Definition

When a sequence has an explicit difinition, finding the behavior of an infinitely long extension of the sequence is more or less the same as taking a limit.

Limit[((Cos[2n])/n),n-> ∞]

When this limit exists, the sequence is said to converge. A formal proof might involve using the Squeeze Thoerem.

-(1/n)<((cos(2n))/n)<(1/n)

SeqBounds = Plot[{1/n,-1/n},{n,1,61},Filling-> {1 -> {{2},{Cyan}}}]

Show[SeqBounds, SeqPlot]

Recursive Definition

When a sequence is defined recursively, trying to take the limit won’t work directly. Suppose the the limit exists. This can’t be garunteed, some sequence grow unbounded, some sequences get stuck in a loop, others just wander randomly forever. But, if it does exist, define the limit as (Subscript[a, ∞]).

(lim_(x->∞ ))(Subscript[a, n])= (Subscript[a, ∞])

To see how this helps find the convergence of recursive, consider the example below.

(Subscript[a, 1])=30  and  (Subscript[a, n])= (1/2)((Subscript[a, n-1])+6)

By creating the sequence with RecurrenceTable[] and taking a decent number terms it is quickly seen that the sequence will converge to 6.

A = RecurrenceTable[{a[1]==30.,a[n]==(1/2)(a[n-1]+6)},
 a,{n,1,12}]

Here’s an illustration of the convergence.

Show[ListPlot[A],
Plot[6,{x,0,12},PlotStyle->{Red,Dotted}]]

When the sequence converges, both (Subscript[a, n]) and (Subscript[a, n-1]) should equal the limit (Subscript[a, ∞]). Replacing both terms in the definition of the sequence produces an equation for this limit.

(Subscript[a, ∞]) = (1/2)((Subscript[a, ∞])+6)

This gives the expected limit of (Subscript[a, ∞])=6.