Introduction to Lists

Comprehension Questions

Math 250 - Math with Mathematica
Christopher Hanusa

Questions for Everyone

2-1. For each of the following Range 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.

Range[Pi]

Range[10,5]

Range[10,30,Pi]

Range[Pi,30,10]

Range[100,0,-8]

2-2. Determine which Range commands give the following lists.

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

{1,3,5,7,9,11}

{1.,1.5,2.,2.5,3.,3.5,4.,4.5}

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

2-3. 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[i,{i,10}]

Table[i,{2,6}]

Table[x^2,{x,Pi,10}]

Table[a,{a,1,10,Pi}]

Table[{x,x^2},{x,3,6}]

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

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

{2 π,2+2 π,4+2 π,6+2 π,8+2 π}

{1,8,27,64,125,216}

{(1/4),(1/5),(1/6),(1/7)}

{(1/10),(1/2),-(1/4)}

{{-3,9},{-2,4},{-1,1},{0,0}}

Challenge Questions

2-5. Give a Range or Table command to give the following lists.

{(π/2),((3 π)/2),((5 π)/2),((7 π)/2),((9 π)/2),((11 π)/2)}

{{0,1,2},{1,3,4},{2,6,8},{3,10,16},{4,15,32}}

{ab+1,-ab+4,ab+9,-ab+16,ab+25}

2-6. Adding numbers:

Use Mathematica to find the sum of the first 10 numbers.

Use Mathematica to create a list where entry number n is the sum of the first n numbers.

What is the sum of the entries in that list?  What is the average of the entries in that list?

Questions for Everyone

2-7. Create the following matrix:

Challenge Questions

2-8. Lists with the same number of entries.

Suppose you have a list named list:

list={12,452,7,33124,623,8,13443,8,23}

How do you create the a list of numbers {1, 2, 3, ...} that has the same number of entries as list?

2-9. Use Mathematica to create a list of lists where list 1 has one 1, list 2 has two 2s, list 3 has three 3s, etc.

Questions for Everyone

2-10. Suppose you wanted a visual representation of the rolls of 200 dice like in Tutorial Section 2.7, but chronologically instead of tallied together.  How would you do this in Mathematica? Should the data points be connected or not?  Why or why not?

2-11. 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.

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

Length[{{1,2,3}}]

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

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

Total[{{1,2,3}}]

Challenge Questions

2-12. There are many commands for that apply to lists.

Take some time to learn about Mean and Median in the Documentation Center. What is the syntax of those commands? Write down (in sentence format) the input(s) they take, the type of output they give, and the rule that is applied to the input(s) to give the output.

2-13. How could you use the commands from Question 2-12 to find the midpoint of a line with the following coordinates?

{{0,0},{2,3}}

2-14. Go to the Documentation Center and read about the RandomChoice command.
Use it to model 1000 flips of a coin that lands on “Heads” or “Tails”.  How many heads came up? How many tails?
Run it a second (or third, fourth, ...) time and see if you get a different answer.

2-15. Consider rolling two dice and taking the sum of the values.  What is the average value for this sum?  What is the average value for the product of two rolled dice?  Three rolled dice?  Four?