More on sequences
A
sequence
is simply an ordered collection of numbers or other Maple expressions separated by commas.
Here is an example of a sequence in Maple. Remember, a sequence can contain any mixture of numbers and other Maple expressions.
> myseq := 1, 5, x, z^2, 3;
You can pick out any member of a sequence by specifying its position in the sequence. For example, to refer to the third member in
myseq
:
> myseq[3];
Generating Sequences
There are several ways to generate sequences in Maple. The first is the method we used above: type in the sequence. This can be inconvenient when we need to generate large sequences, however. When the sequence has a simple pattern, Maple provides some more efficient methods for generating sequences. One such method is the
seq
command:
>
seq( i, i = 6..9 );
squares := seq( i^2, i = 2..5 );
>
Get the idea? In general, the first expression ( i^2 in the second example) is repeated in a sequence, with i changing as specified (from 2 to 5 in the second example). You can use letters other than i if you like.