Documentation Center |
Create an expression sequence
This functionality does not run in MATLAB.
$ a .. b _seqgen(a .. b) $ c .. d step e _seqstep(c .. d, e) f $ n _seqgen(f, n) f $ c step e _seqstep(f, c, e) f $ i = a .. b _seqgen(f, i, a .. b) f $ i = c .. d step e _seqstep(f, i, c .. d, e) f $ i in object _seqin(f, i, object)
$ a..b creates the sequence of integers from a through b.
$c..d step e creates the sequence of numbers from c through d with increment e.
f $ n creates the sequence f,..., f consisting of n copies of f.
f $ c step e creates the sequence f,..., f consisting of trunc(c/e) copies of f.
f(i) $ i = a..b creates the sequence f(a), f(a+1),..., f(b).
f(i) $ i = c..d step e creates the sequence f(c), f(c+e),..., f(c+j*e), with j such that c+j*e <= d and c+(j+1)*e > d.
f(i) $ i in object creates the sequence f(i1), f(i2), ..., where i1, i2 etc. are the operands of the object.
The $ operator is a most useful tool. It serves for generating sequences of objects. Sequences are used to define sets or lists, and may be passed as arguments to system functions. Cf. Example 1.
$ a..b and the equivalent function call _seqgen(a..b) produce the sequence of integers a, a + 1, ... , b. The void object of type DOM_NULL is produced if a > b.
$ c..d step e and the equivalent function call _seqstep(c..d, e) produce the sequence of numbers c, c + e, ... , c + j*e, with j such that c + j*e <= d and c + (j + 1)*e > d. The void object of type DOM_NULL is produced if c > d.
f $ n and the equivalent function call _seqgen(f, n) produce a sequence of n copies of the object f. Note that f is evaluated only once, before the sequence is created. The empty sequence of type DOM_NULL is produced if n is not positive.
f $ c step e and the equivalent function call _seqstep(f, c, e) produce a sequence of trunc(c/e) copies of the object f. Note that f is evaluated only once, before the sequence is created. The empty sequence of type DOM_NULL is produced if trunc(c/e) is not positive.
f $ i = a..b and the equivalent function call _seqgen(f, i, a..b) successively set i := a through i := b and evaluate f with these values. After this (or in case of an error, earlier), the previous value of i is restored.
Note that f is not evaluated before the first assignment. The void object of type DOM_NULL is produced if a > b.
f $ i = c..d step e and the equivalent function call _seqstep(f, i, c..d, e) successively set i := c, i := c + e, ... until the value of i exceeds d and evaluate f with these values. After this (or in case of an error, earlier), the previous value of i is restored.
Note that f is not evaluated before the first assignment. The void object of type DOM_NULL is produced if c > d.
f $ i in object and the equivalent function call _seqin(f, i, object) successively assign the operands of the object to i: they set i := op(object, 1) through i := op(object, n) and evaluate f with these values, returning the result. (n = nops(object) is the number of operands.)
Note that f is not evaluated before the assignments. The empty sequence of type DOM_NULL is produced if the object has no operands.
The "loop variable" i in f $ i = a..b and f $ i in object may have a value. This value is restored after the $ statement returns.
The following sequence can be passed as arguments to the function _plus, which adds up its arguments:
i^2 $ i = 1..5
_plus(i^2 $ i = 1..5)
The 5-th derivative of the expression exp(x^2) is:
diff(exp(x^2), x $ 5)
We compute the first derivatives of sin(x):
diff(sin(x), x $ i) $ i = 0..5
We use ithprime to compute the first 10 prime numbers:
ithprime(i) $ i = 1..10
We select all primes from the set of integers between 1990 and 2010:
select({$ 1990..2010}, isprime)
The 3×3matrix with entries A_{ij} = i j is generated:
n := 3: matrix([[i*j $ j = 1..n] $ i = 1..n])
delete n:
In f $ n, the object f is evaluated only once. The result is copied n times. Consequently, the following call produces copies of one single random number:
random() $ 3
The following call evaluates random for each value of of i:
random() $ i = 1..3
In the following call, i runs through the list:
i^2 $ i in [3, 2, 1]
Note that the screen output of sets does not necessarily coincide with the internal ordering:
set := {i^2 $ i = 1..19}: set; [op(set)]
The $ operator respects the internal ordering:
i^2 $ i in set
delete set:
Arbitrary objects f are allowed in f $ i = a..b. In the following call, f is an assignment (it has to be enclosed in brackets). The sequence computes a table f[i] = i!:
f[0] := 1: (f[i] := i*f[i - 1]) $ i = 1..4: f
delete f:
Apart from the usual sequence generator with the step size 1, _seqstep allows arbitrary integer, rational, or real numbers as step sizes:
1 $ 2 step 0.5
$ 1..2 step .2
f(i) $ i = 1..2 step 1/2
Like in a for-loop, the step size can be negative:
f(i) $ i = 5..1 step -2
In contrast to _seqgen the range bounds in _seqstep can be rational or floating-point numbers:
1 $ 5/2 step 0.5
$ 1.1..2.1 step .2
f(i) $ i = 1/2..5/2 step 1/2
the $-expression returns symbolically, if the given range is symbolic:
x $ n, $ a..b, f(i) $ i = a..b
f, object |
Arbitrary MuPAD^{®} objects |
n, a, b | |
c, d, e |
integer, rational, or floating-point numbers |
i |
An identifier or a local variable (DOM_VAR) of a procedure |