Mathematical Applications · BE5B15MAA · Topic 11 of 13
Creation and manipulation of Lists, functions and Lists: Table, Part, Map, Apply
Week 11. Table builds a list, Part takes it apart, and Map, Apply and Select act on all of it at once.
Key ideas
Building lists
Range[a,b,step] gives numbers; Table[expr,{i,imin,imax,step}] evaluates expr for every i and also accepts an explicit list {i,{1,5,7,8}}. Table[x^i,{i,1,15,2}] gives the odd powers. A list of lists is a matrix, and Dot multiplies it with a vector.
Part and nested lists
alist[[3]] is Part[alist,3]. For nested lists give several indices: {1,2,4,{2,5,{34,1}}}[[4,2]] is 5, First and Last pick the ends and [[−2]] counts from the end. An element can be replaced: list[[5,2]]=value.
Map, Apply and Select
f/@list is Map and gives {f[a],f[b],...}; f@@list is Apply and replaces the head List by f, so Plus@@{1,2,3,5} adds and Power@@{a,b,c,d} builds a^b^c^d. Select[list,test] keeps the elements for which the test gives True, for example Select[{1,2,4,7,6,2},#>2&]. Note that {1,3,4}.{a,b,c} is a+3b+4c while {1,3,4}*{a,b,c} acts element by element.
In one line: Think of a list as one object: Table creates it, Part indexes it, Map and Apply send a function through it.
Practice with worked solutions
Question 1
ListPlot[{4, 9, 16}] draws one point per value of a one-dimensional list. What x-coordinate does the point with value 16 get?
Worked solution
Answer: 3
For one-dimensional data ListPlot uses the position in the list as x, starting at 1.
More Mathematical Applications practice in Ucenly
Sources
Written by Ucenly. Based on the BE5B15MAA course materials:
- Course card BE5B15MAA (Bílá kniha), p. 1
- Seminar notebook, state of 28 Mar 2019 (seminar2832019.nb), text extract, p. 1
- Introduction to Wolfram Mathematica (Intro_Wm.nb inside Intro_WM.rar), text extract, p. 1
- Programming tutorial in Czech (programing-tutorial.nb inside Examples.zip), text extract, p. 1