Maple Tutorials
Elmer K. Hayashi
Created Spring 2001
Working with Sequences
Working with Sequences
To generate the terms of a sequence that is defined by a simple defining formula, we use the command seq.
For example if then the first twenty terms of the sequence can be generated as follows:
> seq((2*n+1)/(3*n+4),n=1..20);
Note that the first parameter is the formula for the nth term of the sequence, and the second parameter is the range for n.
The above gives the exact value of each term, but if we wish to guess the limit of the sequence it is often helpful to look at
the decimal approximation for each term by using evalf.
> seq(evalf((2*n+1)/(3*n+4)),n=1..20);
It is often helpful to save an expression as a named expression to save typing and also to check that the expression has been typed correctly. For example, we could name the expression representing the formula for the nth term of the sequence as follows:
> a:=(2*n+1)/(3*n+4);
We can see from the last output that we have typed in the expression for the nth term correctly, or if there is an error, we should be able to see it is wrong and make the necessary corrections. Now to generate terms of the sequence, we need only type
> seq(a,n=1..30);
> seq(evalf(a),n=1..30);
The limit of a sequence can be found using the limit command with second parameter n=infinity.
> limit(a,n=infinity);
One example of a sequence that does not have a simple defining formula is one that involves a product with an increasing number of factors such as 1*3*5***(2n-1). A special command to deal with such products is called product. The first parameter is the formula for each factor, and the second parameter is the range of the variable. So we obtain
> product(2*k-1,k=1..2);
> product(2*k-1,k=1..3);
> product(2*k-1,k=1..4);
Now we can combine seq and product to obtain the terms of the sequence a[n]=1*3*5*(2n-1)
> seq(product(2*k-1,k=1..n),n=1..10);
The limit of this sequence is evidently infinity.
> limit(product(2*k-1,k=1..n),n=infinity);
The product n! is defined in Maple as a function called factorial. Care should be taken with the use of this function since the value of factorial grows to an unmanageable size rapidly.
> seq(factorial(n),n=1..9);
A second example of a sequence that does not have a simple defining formula is one that is defined recursively (terms are defined as a function of previous terms). For example is a recursively defined sequence. One can generate terms of this sequence by using a function with formula obtained by replacing in the formula of the sequence by the function variable x. Thus
> f:= x -> 1/(1+x);
Now a2 = f(a1) = f(1), a3 = f(a2), etc.
> f(1);
> f(1/2);
> f(2/3);
> f(3/5);
A loop can be used to generate the terms of the sequence as follows
> s:=1; for k from 2 to 9 do s:= f(s); od;