Skip to main content

Lists and Sequences

List basics​

Separate values with commas and surround them with square brackets to create a list.

1
[1,2,5][1,2,5]
2
[(1,2),(4,1)][(1,2),(4,1)]

Lists may also contain points or vectors, but every item in one list must have the same type. Placing a list inside an expression draws several graphs at once.

1
x=[2,4,7]x=[2,4,7]
2
y=[1,3]x+[3,2]y=[1,3]x+[3,2]
3
[(1,2),(2,4)][(1,2),(2,4)]
4
(x,y) for x=[0,1],y=[0,1](x,y)\ \mathrm{for}\ x=[0,1],y=[0,1]
Loading graph…
Open in Desmos ↗

Creating lists​

Three periods abbreviate an arithmetic sequence and allow its length to depend on another variable.

1
[1,2,...,5]=[1,2,3,4,5][1,2,...,5]=[1,2,3,4,5]
2
[3,3.1,...,3.5]=[3,3.1,3.2,3.3,3.4,3.5][3,3.1,...,3.5]=[3,3.1,3.2,3.3,3.4,3.5]
3
n=4n=4
4
[1,2,...,n]=[1,2,3,4][1,2,...,n]=[1,2,3,4]

for provides list-comprehension syntax.

1
[2i for i=[1,2,4]]=[2,4,8][2i\ \mathrm{for}\ i=[1,2,4]]=[2,4,8]
2
[1 for i=[1,2,...,100]][1\ \mathrm{for}\ i=[1,2,...,100]]

Lists in expressions​

Desmos substitutes each element into the expression and draws the resulting graphs.

1
y=[3,4]y=[3,4]
2
x2+y2<[1,3]x^2+y^2<[1,3]
3
A=[0.5,1]A=[0.5,1]
4
2sin⁡(Ax)2\sin(Ax)
Loading graph…
Open in Desmos ↗

Multiple lists are paired by position: ([1,2],[3,4]) draws (1,3)(1,3) and (2,4)(2,4). Use for when you need every combination.

Using for​

1
y=ax for a=[1,2,3]y=ax\ \mathrm{for}\ a=[1,2,3]
2
(x,y) for x=[1,2,3,4],y=[2,3,4](x,y)\ \mathrm{for}\ x=[1,2,3,4],y=[2,3,4]
Loading graph…
Open in Desmos ↗

See for and with for more details.

Selecting elements​

Append an index in square brackets. Desmos uses one-based indexing.

1
A=[2,4,5]A=[2,4,5]
2
A[1]=2A[1]=2
3
A[3]=5A[3]=5
4
B=[1,3,5,8]B=[1,3,5,8]
5
∑n=14B[n]=17\sum_{n=1}^{4}B[n]=17

Indices may themselves be lists, ranges, or conditions.

1
A=[2,4,6,8,10]A=[2,4,6,8,10]
2
B=[1,2]B=[1,2]
3
A[2,...,4]=[4,6,8]A[2,...,4]=[4,6,8]
4
A[3,...]=[6,8,10]A[3,...]=[6,8,10]
5
A[B]=[2,4]A[B]=[2,4]
6
C=[1,2,...,10]C=[1,2,...,10]
7
C[C>8]=[9,10]C[C>8]=[9,10]

Use [1,3,4].count or count([1,3,4]) to obtain a list’s length.