6.1.2 Making a sequence or a list
The seq command or
$ operator can create
a sequence or a list.
-
To create a sequence, seq takes three mandatory arguments
and one optional argument:
-
expr, an expression depending on a parameter.
- k, the parameter.
- a..b, a range of values.
The range can be combined with the parameter into one argument of
k=a..b.
- Optionally p, a step size (by default 1 or -1, depending
on whether b>a or b<a). This is only allowed
if the previous two arguments are combined into one, k=a..b
This is Maple-like syntax.
- seq(expr,k,a..b) or
seq(expr,k=a..b ⟨,p⟩)
returns the sequence formed by the values of expr, as k
changes from a to b in steps of p.
Alternatively, a sequence can be created with the infixed $ operator.
Namely, expr$(k=a..b)
returns the sequence formed by the values of expr as k
changes from a to b. As a special case, expr$n
creates a sequence consisting of n copies of expr.
There are two ways to create a list with seq.
-
seq can take four mandatory arguments
and one optional argument:
-
expr, an expression depending on a parameter.
- k, the parameter.
- a, the beginning value of the parameter.
- b, the ending value of the parameter.
- Optionally p, a step size (by default 1 or -1, depending
on whether b>a or b<a).
This is TI-like syntax.
- seq(expr,k,a,b ⟨,p⟩)
returns the list consisting of the values of expr, as k
changes from a to b in steps of p.
- As a special case, seq(expr,n)
creates a list consisting of n copies of expr.
- Alternatively, seq can take two arguments:
-
expr, an expression.
- n, a positive integer.
- seq(expr,n)
returns the list consisting of n copies of expr.
Remarks.
In Xcas mode, the precedence of $ is not the
same as it is, for example, in Maple. In case of doubt,
put the arguments of $ in parenthesis.
For example, the following commands are equivalent:
or
With Maple syntax, j,a..b,p is not valid.
To specify a step p for the variation of
j from a to b, use j=a..b,p or use the TI syntax
j,a,b,p and get the sequence from the list with
op(…).
Examples
To create a sequence:
or:
or:
To create a list:
To create a sequence:
To create a list:
or:
|
| ⎡
⎣ | 1,3.375,8.0,15.625,27.0 | ⎤
⎦ |
| | | | | | | | | | |
|
To create a list with several copies of the same element:
To create a sequence with several copies of the same element:
or:
Examples of sequences being used
Find the third derivative of ln(t) (see Section 13.2.1):
l:=[[2,3],[5,1],[7,2]]
seq((l[k][0])$(l[k][1]),k=0..size(l)-1) |
|
| ⎛
⎝ | 2,2,2 | ⎞
⎠ | , | ⎛
⎝ | 5 | ⎞
⎠ | , | ⎛
⎝ | 7,7 | ⎞
⎠ |
| | | | | | | | | | |
|
then:
Transform a string into a list of its characters:
chn:="abracadbra":;
seq(chn[j],j,0,size(chn)-1) |
|
| ⎡
⎣ | “a”,“b”,“r”,“a”,“c”,
“a”,“d”,“a”,“b”,“r”,“a” | ⎤
⎦ |
| | | | | | | | | | |
|