Lists and tables
Lists of data arise in many circumstances, e.g., a series of measurements made as a function of time, etc. In Mathe-
matica, a list is simply a collection of objects stored between brackets, and assigned to a name. The elements of a
list can be whatever you want:
In[262]:=tters = 8a, b, c, d<
Out[262]=1319.77, b, c, d<
In[263]:=tegers = 81, 2, 3<
Out[263]=1, 2, 3<
reals = 810.0, 44.7, 61.3, 76.5, 88.1<
In[264]:=
Out[264]=10., 44.7, 61.3, 76.5, 88.1<
Lists can be generated using the Table command, which takes two arguments. The first is the expression to be
evaluated, and the second gives the variable and the its range. Here are a few examples:
In[265]:= create list of squares of i for i = 1 to i = 10 *L
squares =

[email protected]^2, 8i, 1, 10
3 5 7 9
In[268]:= note 1êi was not evaluated at i = 10 because stepsize was 2 *L
H* here we do the same thing using a function that we define first: *L

[email protected]_D := 1 ê x;
recip =

[email protected]@xD, 8x, 1, 10, 2
3 5 7 9
The Length command gives the length of a list:
In[270]:

[email protected]
Out[270]=0
In[271]:

[email protected]
Out[271]=
There are a number of commands for extracting particular elements from a list:
In[272]:= First and last extract the first and last elements, respectively, from a list: *L

[email protected]
Out[272]=319.77 2 mathematica_lesson3.nb
In[273]:

[email protected]
Out[273]=
In[274]:= second and third element: *L

[email protected]@2DD

[email protected]@3DD
Out[274]=
Out[275]=
In[276]:= second and third from last element *L

[email protected]@-2DD

[email protected]@-3DD
Out[276]=
b
Out[277]=
H* Make a new list using the first 3 elements using the Take command: *L
In[278]:=

[email protected], 3D
Out[278]=1319.77, b, c<
In[279]:= Make a new list using the last 3 elements using the Take command: *L
In[280]:

[email protected], -3D
Out[280]=b, c, d<
Arithmetic operations are distributive over lists:
In[281]:=* integers
Out[281]=2, 4, 6<
In[282]:=tegers + 10
811, 12, 13<
Out[282]=

[email protected]
In[283]:=
Out[283]=10, 9, 8, 7, 6, 5, 4, 3, 2, 1<
You can add (append to) elements and join lists:
In[284]:

[email protected], 4D
Out[284]=1, 2, 3, 4<
In[285]:

[email protected], xD
Out[285]=1319.77, b, c, d, x<
In[286]:=uits = 8apples, oranges, pears