SequenceVector
Returns a vector with an arithmetic sequence of integers.
Syntax
-
SequenceVector(n)
-
n
is a positive integer
-
-
SequenceVector(a, b[, d])
-
a
andb
are integers -
d
is a positive integer
-
Description
If n
is a positive integer, then SequenceVector(n)
returns the vector containing the first n
positive numbers in order.
If a
and b
are integers, then SequenceVector(a, b)
returns the list containing all integers from a
to b
(inclusively) in order. If b < a
, the sequence is decreasing. SequenceVector(a, b, k)
returns the integers from a
to b
with step k
, that is, the integers a, a ± k, a ± 2k, ...
in the direction of b
but never exceeding b
.
Examples
SequenceVector
is often used to generate arbitrary sequences by means of the @
operator and function objects:
SequenceVector(10) @ sqr
(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
SequenceVector(10) @ prime
(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
SequenceVector(10) @ (n ↦ n^n)
(1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489, 10000000000)
ℙ ≔ SequenceVector(1000000) @ prime;
count(ℙ, p ↦ ∑(digits(p)) = 10)
1121
Another approach is to use the compute
function:
compute(n!, n, 1, 10)
1 2 6 24 120 720 5040 40320 362880 3628800
SequenceVector
can also be used to plot a sequence of numbers in a diagram:
D ≔ ❨3.1, 2.9, 3.5, 3.2, 3.4, 3.0, 2.9, 3.7, 3.2, 3.5❩; plot(MatFromCols(SequenceVector(#D), D))