Functions and the Map command

Comprehension Questions

Math 250 - Mathematical Computing
Christopher Hanusa

5-1. Before evaluating the following lines of code, anticipate what will be the result will be.  
     After evaluating the code, understand why the output is what it is and compare it with your expectations.

Sin@Pi

Map[Sin,{0,Pi/2,Pi,3Pi/2}]

Map[Sin, Pi]

Range@Prime@10

Map[Prime,{1,2,4,8}]

Map[f,Map[g,Range[5]]]

f/@g/@h/@Range[5]

5-2. Explain the difference in the outputs between Framed @ {x,y,z} and Framed /@ {x,y,z}.

5-3. Use the functions Prime, Map, and Range commands to generate a list of the 100th, 200th, ... up to 2000th prime numbers.

5-4. If there is some coordinate data ((x,y)-pairs) in the lists data1, data2, data3, and data4, how can you make a list of scatterplots of these datasets in one line of code?

5-5. What do the following functions do?

f1[x_]:=Length[Range[Prime[x]]]

f2[x_,y_]:={x,y}

5-6. Define a function that takes as input a number n and outputs the (2^n)-th prime number

5-7. Define a function that takes as input three variables and outputs the sum of the first and third number and divides by the second.

5-8. Define a function that takes as input a list and outputs the average value of the entries.  Use the function Total.

5-9. What is wrong with the following code?  
      It is supposed to take in a number, divide by two, then give the floor of that number.
      For example, the output for an input of 19 should be Floor[19/2]=Floor[9.5]=9.

fountainOfYouth[x]:=Floor[x/2]
fountainOfYouth(19)