Previous Page Next Page Contents

$ -- create an expression sequence

Introduction

$a..b creates the sequence of integers from a through b.

f $n creates the sequence f, ... , f consisting of n copies of f.

f(i) $i = a..b creates the sequence f(a), f(a+1), ... , f(b).

f(i) $i in object creates the sequence f(i1), f(i2), ..., where i1, i2 etc. are the operands of the object.

Call(s)


$a..b _seqgen(a..b)

f $n _seqgen(f, n)

f $i = a..b _seqgen(f, i, a..b)

f $i in object _seqin(f, i, object)

Parameters

f, object - arbitrary MuPAD objects
n, a, b - integers
i - an identifier or a local variable (DOM_VAR) of a procedure

Returns

an expression sequence of type "_exprseq" or the void object of type DOM_NULL.

Overloadable:

a..b, f, n, i, object

Related Functions

_exprseq, null

Details

Example 1

The following sequence can be passed as arguments to the function _plus, which adds up its arguments:

>> i^2 $ i = 1..5
                              1, 4, 9, 16, 25
>> _plus(i^2 $ i = 1..5)
                                    55

The 5-th derivative of the expression exp(x^2) is:

>> diff(exp(x^2), x $ 5)
                         2         3      2        5      2
              120 x exp(x ) + 160 x  exp(x ) + 32 x  exp(x )

We compute the first derivatives of sin(x):

>> diff(sin(x), x $ i) $ i = 0..5
             sin(x), cos(x), -sin(x), -cos(x), sin(x), cos(x)

We use ithprime to compute the first 10 prime numbers:

>> ithprime(i) $ i = 1..10
                    2, 3, 5, 7, 11, 13, 17, 19, 23, 29

We select all primes from the set of integers between 1990 and 2010:

>> select({$ 1990..2010}, isprime)
                         {1993, 1997, 1999, 2003}

The 3 x 3 matrix with entries A[i,j] = i*j is generated:

>> n := 3: matrix([[i*j $ j = 1..n] $ i = 1..n])
                               +-         -+
                               |  1, 2, 3  |
                               |           |
                               |  2, 4, 6  |
                               |           |
                               |  3, 6, 9  |
                               +-         -+
>> delete n:

Example 2

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
                 427419669081, 427419669081, 427419669081

The following call evaluates random for each value of of i:

>> random() $ i = 1..3
                 321110693270, 343633073697, 474256143563

Example 3

In the following call, i runs through the list:

>> i^2 $ i in [3, 2, 1]
                                  9, 4, 1

Note that the screen output of sets does not necessarily coincide with the internal ordering:

>> Set := {1, 2, 3, 4}: Set, [op(Set)]
                        {1, 2, 3, 4}, [4, 3, 2, 1]

The $ operator respects the internal ordering:

>> i^2 $ i in Set
                                16, 9, 4, 1
>> delete Set:

Example 4

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
                                 table(
                                   4 = 24,
                                   3 = 6,
                                   2 = 2,
                                   1 = 1,
                                   0 = 1
                                 )
>> delete f:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000