Mathematica Shortcuts and Modifying Lists

Comprehension Questions.

Math 250 - Math with Mathematica
Christopher Hanusa

3-1. For each of the following Table commands, complete the following sub-questions.
(a) BEFORE EVALUATING THE COMMAND, what list do you expect the command to give?  Or do you expect an error?
(b) Now, evaluate the command.  Did it do what you expect it to do?
(c) If not, figure out what went wrong with your reasoning.

Table[{s,7,9},{t,3,5}]

Table[xy,{x,2,4},{y,5,7}]

Table[Plot[x^n,{n,-2,2}],{x,1,10}]

Table[CountryData[country,"Population"],{country,{"France","United States","China"}}]

3-2. Determine which Table commands give the following lists.  There are multiple solutions for each one.

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

{{5,5,5},{6,6,6},{7,7,7},{8,8,8},{9,9,9},{10,10,10}}

{{"France","has",(Quantity[64101308, "people", people, "People"])},{"United States","has",(Quantity[322422965, "people", people, "People"])},{"China","has",(Quantity[1364773138, "people", people, "People"])}}

3-3. What is the difference between the following two lines of code? Explain the difference in outputs.

Table[Plot[x^n,{x,-2,2}],{n,1,10}]

Table[Plot[x^n,{n,-2,2}],{x,1,10}]

3-4. For each of the following commands, complete the following sub-questions.
(a) What list do you expect the command to give?  Or do you expect an error?
(b) Now evaluate the command.  Did it do what you expect it to do?
(c) If not, figure out what went wrong with your reasoning.

Flatten[{{{{1},2},3},4}]

Flatten[{{{{1},2},3},4},2]

Append[{1,2,3,4},{1}]

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

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

3-5. Write the code that takes entries 5 through 15 of this list primes

primes=Table[Prime[n],{n,1,20}]

3-6. Here are two lists which represent the x- and y-coordinates of points, and an incorrect Table command that hopes to collect the points into a list of ordered x,y pairs.  Figure out what is wrong with the command and fix it.

x={1,2,3,4,5}
y={2,5,10,17,26}
points=Table[{x[i],y[i]},{i,1,Length[x]}]

3-7. Write out in English the first 10 multiples of three.  You may find the command IntegerName useful.

3-8. What should you type to extract the list {{a,b},{q,r}} from veryverydeeplist?

Exploration Question

3-9. Visit the Documentation Center entry for Getting Pieces Of Lists to see other commands Mathematica uses to take pieces of lists.  What does the ;; operator do?