Previous Up Next

5.43.2  Define a list: makelist

See also section 5.43.41.

A list can be defined by listing its elements, separated by commas, between square brackets.
Input:

L1 := [1,2,3]

To define the empty list, simply enter the brackets.
Input:

L0 := []

L0 is now the empty list.

The subsop command (see section 5.43.14) can be used to modify lists. You can also redefine elements (or define new elements) with :=.
Input:

L1

Output:

[1,2,3]

Input:

L1[2] := 16

then:

L1

Output:

[1,2,16]

Input:

L0

Output:

[]

Input:

L0[5] := 16

then:

L0

Output:

[0,0,0,0,0,16]

You can also define a list with the makelist command.
Input:

makelist(4,1,3)

creates a list with entries 4, from integers 1 to 3. This is the same as [4 $ 3].
Output:

[4,4,4]

Input:

makelist(4,2,7)

creates a list with entries 4, from integers 2 to 7. This is the same as [4 $ 6].
Output:

[4,4,4,4,4,4]

Input:

makelist(x -> x^2,1,10,2)

creates a list of the squares of the numbers, starting at 1, ending at 10, and going in steps of 2. This is the same as [(k^2) $ (k = 1..10,2)]. Output:

[1,9,25,49,81]

Previous Up Next