Lists I

Introduction

Lists are delimited by"{" and "}".
Sets,vectors, matrices etc. are all special kinds of lists.

{1,2,3,4}

{{1,2},{3,4}}

lst={{x,{y,z}},"dog",{},4}

FullForm[lst]

Creating Lists: The "Table" Command

Table[i,{i,1,10}]

Table[i^3,{i,0,-5,-.7}]

RandomReal[{-10,10},3]

RandomReal[{0,1},{3,4}]

tab=Table[i j,{i,1,5},{j,0,10}]

Length[tab]

Dimensions[tab]

Flatten[tab]

Length[%]

tab2=Table[{i,j,k},{i,1,3},{j,1,2},{k,-1,1}]

Length[tab2]

Flatten[tab2]

Length[%]

Flatten[tab2,1]

Length[%]

Flatten[tab2,2]

Length[%]

Table[i+j,{i,2,5},{j,1,i-1}]

Table[i+j,{i,1,5},{j,1,i}]

Accessing Parts of Lists

tab=RandomInteger[{-100,100},{3,2}]

FullForm[tab]

tab[[1]]

tab[[1,2]]

tab[[All,1]]

sols=Solve[2x==x^2-5,x]

FullForm[sols]

sols[[1]]

sols[[1,1]]

sols[[1,1,2]]

expr=x+y^3-z

FullForm[%]

expr[[2]]

FullForm[%]

expr[[2,2]]

Accessing Parts of Lists, continued

tab=Table[i^2,{i,6}]

Take[tab,{2,4}]

tab[[2;;4]]

Take[tab,3]

Take[tab,-2]

Drop[tab,{2,4}]

Drop[tab,-2]

First[tab]

Last[tab]

Rest[tab]