Creating a list by using a function

### 6.3.2 Creating a list by using a function

The makelist command creates lists built from values of a function.

- makelist takes three mandatory arguments and one optional argument:
  - f, a function (see Section 8.2.1).
  - a and b, two real numbers.
  - Optionally p, a step size (by default 1 if b>a and −1 if b < a).
- makelist(f,a,b ⟨,p⟩) returns the list [f(a),f(a+p),…,f(a+k p)] with k such that

  a<a+k p ≤ b <a+(k+1) p or a>a+k p ≥ b >a+(k+1) p.

#### Examples

(In these examples, purge x if x is not symbolic.)

makelist(x->x^2,3,5)

or:

makelist(x->x^2,3,5,1)

or:

h(x):=x^2:; makelist(h,3,5,1)

| ⎡ ⎣ | 9,16,25 | ⎤ ⎦

makelist(x->x^2,3,6,2)

| ⎡ ⎣ | 9,25 | ⎤ ⎦

makelist(4,1,3)

| ⎡ ⎣ | 4,4,4 | ⎤ ⎦

The above command line regards 4 as the constant function, and so creates a list with entries 4, from integers 1 to 3. The command

[4$3]

is an equivalent.