Makelist Primitive

Another way to construct a list programmatically is to use the makelist primitive.

See makelist.

This primitive has the format

 makelist( f(x), x, x1, x2, step )

The first four arguments are required; the last argument, step, is optional. Makelist creates a list by constructing a temporary variable using the name you specified in the argument x, and setting x equal to all numbers from x1 to x2 and repeatedly evaluating the expression f(x). The following definition creates a list of the integers from 1 to 6 (i.e., [1,2,3,4,5,6]):

List:=makelist(n,n,1,6)

Similarly, the following definition creates a list of the integers 1 to 6 squared (i.e., [1,4,9,16,25,36]):

List:=makelist(n*n,n,1,6)

Makelist normally increments the variable x by one after each iteration. You can specify a different step size by including a value for the step argument. The following expression creates a list of even numbers between 0 and 10 (i.e. [0,2,4,6,8,10]):

List:=makelist(n,n,0,10,2)

The expression you use for f(x) can be a complete equation or it can reference other functions you have defined.

See Create Lists.