Lists and Tables

Lists

Basics

{1, 2, 3, 4, 5}

{1, 2, 3, 4, 5} + 10

10 + {1, 2, 3, 4, 5}

{1, 2, 3, 4, 5}   10

{1, 2, 3, 4, 5}/10

10/{1, 2, 3, 4, 5}

x^{1, 2, 3, 4, 5}

{1, 2, 3, 4, 5}^x

{1, 2, 3, 4, 5}^x /. x -> 2

{{1, 2}, {3, 4}, {5, 6}}

MatrixForm[{{1, 2}, {3, 4}, {5, 6}}]

{{1, 2}, {3, 4}, {5, 6}}^x

x^{{1, 2}, {3, 4}, {5, 6}}

{{1, 2}, {3, 4}, {5, 6}}/10

Transpose[{{1, 2}, {3, 4}, {5, 6}}]

MatrixForm[Transpose[{{1, 2}, {3, 4}, {5, 6}}]]

Sqrt[{{1, 2}, {3, 4}, {5, 6}}]

Round[Sqrt[{{1, 2}, {3, 4}, {5, 6}}]]

Handling Lists

Length[{5, 4, 3, 2, 1, 0}]

Length[{{1, 2}, {3, 4}, {5, 6}}]

Reverse[{3, 2, 1, 0}]

Reverse[{{1, 2}, {3, 4}, {5, 6}}]

Sort[{3, 5, 7, 0, 1, 2, -3}]

Sort[{s, e, m, i, n, a, r}]

x = {1, 3, {2, 5}, 7, 8, {{1, 2}, {3, 4}, {5, 6}}}

First[x]

Last[x]

x[[3]]

x[[6]]

x[[6, 1]]

x[[6, 1, 2]]

Part[x, 6]

Part[x, -2]

Part[x, {2, 6}]

Take[{{1, 2}, {3, 4}, {5, 6}}, 2]

Take[{{1, 2}, {3, 4}, {5, 6}}, -2]

Drop[{{1, 2}, {3, 4}, {5, 6}}, 1]

x

Drop[x, 3]

Drop[x, -2]

Drop[x, {2, 5}]

Insert[{{1, 2}, {3, 4}, {5, 6}}, {4.2, 4.7}, 3]

giants = {nishi, motoki, kiyohara, matsui, hirosawa, takahasi, kawai, 
        murata, saito}

Length[giants]

Sort[giants]

giants[[4]]

kyojin = Prepend[giants, nagashima]

ReplacePart[giants, shimizu, 2]

Range[4]

Range[2, 7]

Range[2, 4, 0.5]

Position[giants, matsui]

Position[giants, takahasi]

Apply[g, {1, 2, 3}]

Apply[g, {{1, 2}, {3, 4}, {5, 6}}]

Apply[Plus, {1, 2, 3}]

Apply[Plus, {{1, 2}, {3, 4}, {5, 6}}]

Apply[Times, {1, 2, 3, 4}]

Map[g, {1, 2, 3}]

Map[g, {{1, 2}, {3, 4}, {5, 6}}]

Map[Sqrt, {1, 2, 3, 4}]

ListPlot[{1, 4, 3, 7, 5, 2, 6}]

ListPlot[{1, 4, 3, 7, 5, 2, 6}, PlotJoined -> True]

ListPlot[{{1, 2}, {4, 3}, {2, 8}, {6, 4}}, PlotJoined -> True]

ListPlot[{{1, 2}, {2, 8}, {4, 3}, {6, 4}}, PlotJoined -> True]

Tables

Making Tables

Table[x, {5}]

Table[i, {i, 5}]

Table[1/n, {n, 1, 10}]

Table[x^i, {i, 0, 10, 2}]

Table[{i, j}, {i, 1, 3}, {j, 2, 3}]

Table[N[1/n], {n, 1, 5, 1}]

TableForm[%]

Table[{x, N[Sqrt[x]]}, {x, 0, 9, 1}]

% // TableForm

Table[{{i, j, i + j}}, {i, 0, 2}, {j, 5, 7}]

TableForm[%]

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

% // TableForm

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

Flatten[%, 1]

ListPlot[%]

Plot[Evaluate[Table[x^n, {n, 4}]], {x, -2, 2}];

Repeated Application of Functions

Nest[Sqrt, 2, 1]

Nest[Sqrt, 2, 2]

Nest[Sqrt, 2, 3]

NestList[Sqrt, 2, 3]