Lists of Objects
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Lists (of domain type
DOM_LIST) are ordered
collections of an arbitrary number of arbitrary MuPAD® objects,
except for sequences and the null object.
In MuPAD, the mathematical construct of an n-tuple
is implemented as the data type
consist of an arbitrary (finite) number of arbitrary objects, with
the exception of expression sequences,
which are split into their operands when placed into a list.
Unlike sets, lists can contain multiple copies of the same element. The order of elements in a list is preserved.
Lists can be empty.
To create a list for our first example, we use the operator
L := [x_.i $ i=1..10]
This list contains 10 elements:
The fifth element of the list is x5 and the list of elements from x3 through x6 can also be accessed very easily:
To change an element of the list, we use the indexed form on the left hand side of an assignment:
L := 5
Note that this assignment only changes
Likewise, we can change a sublist by assigning another list to it. This may change the length of the list:
L[3..6] := [1, 2]
Using a list as a function symbol creates the list obtained
by using each list element as a function symbol for the operands used,
[f, g](x, y) results in
L is a list, the number of
L can be determined by calling
Individual elements of the list are accessed in the form
when counting from the beginning or
when counting from the end. Trying to access an element “outside”
the list or
L raises an error.
Continuous sub-lists can be extracted by using a range in an indexed access:
[L, L, L];
L without its first and last element.
Both forms of indexed access can also be used as the left hand side of an assignment, cf. Example 1.
Lists can be concatenated with the dot operator, as in
. L2 or its functional form,
Assigning a list to a list of identifiers is possible and results
in a simultaneous assignment, cf.
The operands of a list are its elements.
The most direct way of creating a list is to place a sequence
of MuPAD objects (separated by commas) between rectangular brackets,
[1, 2, 3].