Lists
Using curly braces you can create a list of several objects (e.g. points, segments, circles).
-
L = {A, B, C}
gives you a list consisting of three prior defined points A, B, and C. -
L = {(0, 0), (1, 1), (2, 2)}
produces a list that consists of the entered points and also creates these nameless points. -
The short syntax
..
creates a list of successive integers: e.g.-5..5
creates the list {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}. -
When a rectangular set of cells in the spreadsheet is filled with data, the short syntax
:
creates the list of the data contained in the portion of the spreadsheet defined by the first and last given cell. The list is filled by columns, e.g.A1:A5
creates the list containing the data {A1, A2, A3, A4, A5} andA1:B5
creates the list containing the data {A1, A2, A3, A4, A5, B1, B2, B3, B4, B5}.
|
Accessing Elements of Lists
To access particular elements of a list you can use the Element Command or the simplified syntax shown in the example below:
Let list = {1, 2, 3, 4, 5}
, then:
-
list(1)
returns the first element of the list: 1 -
list(2)
returns the second element of the list: 2 -
…/…
-
list(-1)
returns the last element of the list: 5 -
list(-5)
returns the first element of the list: 1 -
list(0)
returns undefined, as well aslist(k)
for k > 5 or k < -5
Comparing Lists of Objects
You can compare two lists of objects by using the following syntaxes and commands:
-
List1 == List2
: checks if the two lists are equal as ordered tuples, and yields true or false. -
List1 != List2
: checks if the two lists are not equal as ordered tuples, and yields true or false. -
Unique[list1] == Unique[list2]
orlist1 \ list2 == {}
: checks if the two lists are equal as sets (i.e. all repeated elements are ignored, as well as the elements order) and yields true or false. -
Sort[list1] == Sort[list2]
: checks if the two lists are equal as multisets (i.e. the elements order is ignored) and yields true or false.
List Operators
<Object> ∈ <List>
: returns true if Object is an element of List
<List1> ⊆ <List2>
: returns true if List1 is subset of List2
<List1> ⊂ <List2>
: returns true if List1 is a strict subset of List2
<List1> \ <List2>
: creates the set difference of List1 and List2
Apply Predefined Operations and Functions to Lists
If you apply Predefined Functions and Operators to lists, you will always get a new list as a result.
Addition and subtraction
-
List1 + List2
: adds the corresponding elements of two lists.The two lists need to be of the same length.
-
List + Number
: adds Number to every element of List. -
List1 – List2
: subtracts the elements of List2 from corresponding elements of List1.The lists need to be of the same length.
-
List – Number
: subtracts Number from every element of List.
Multiplication and division
-
List1 * List2
: multiplies the corresponding elements of two lists.The lists need to be of the same length. If the two lists are compatible matrices, matrix multiplication is used.
-
List * Number
: multiplies every List element by the given Number. -
List1 / List2
: divides the elements of List1 by the corresponding elements of List2.The two lists need to be of the same length.
-
List / Number
: divides every List element by Number. -
Number / List
: divides Number by every element of List.
See also Vector product. |
Other examples
-
List ^ 2
: squares every element of List. -
2 ^ List
: creates a list of powers of two, using the List elements as exponents. -
List1 ^ List2
: creates a list containing a^b, where a and b are corresponding elements of List1 and List2. -
sin(List)
: applies the sine function to every element of List.
User defined functions can be applied the same way as well.