Statistical computing: Homework 1

This is the first of many short homework. It is due Jan 19th, 1998.

Grading policy:

My goal is to make sure you understand the concepts from each week as we go along. So it is important to do it immediately. To encourage you, I will take off 2/10 for each day late. So turn it in by the following Friday for any positive credit. Even if you don't finish it by ``zero points day,'' you will still need to finish it to complete the course.

Homework writeups:

Expect to spend about 1/2 of your time programming and 1/2 of your time writing up what you did. You should of course write up your results using LaTeX. Edit your code into your latex file and then use the \tt command to make it look like typewriter output. (This is the usual convention for presenting code.) Your write up should be detailed enough such that if I were to give it to another student he/she could reproduce your results exactly. (Including any mistakes you might have made!)

  1. Code the two functions that compute the absolute value in class. Call them absoSq and absoIf. (Recall the first computed the square and then the squareroot. The second tested if x was greater than 0.) Check the function on various values and see if they both work.
    1. If you only checked the values, 3, 4.674 and 10000, do you have confidence that your functions work?
    2. Print out the help for the unix.time command (staple it to the end of your homework.) Also read the help on lapply and rnorm.
    3. Run the following command:

      and

      What do the above commands do? Which runs faster, absoSq or absoIf? Why do you think this is the case?

    4. Run absoSq(-2+3*1i) and absoIf(-2+3*1i). What is happening?

  2. The Fibonacci are defined as F(x) = F(x - 1) + F(x-2). This inductive definition requires that we specify the values for x=0 and x=1. Let them be zero and one respectively.
    1. Program up the Fibonacci numbers.
    2. Find the running time for x=1,2,3,4,5,10,15,20,25,30,35,40, etc. Plot the running time against x. What shape does it follow?
    3. Plot the log running time against x. What is the slope? How does this relate to the shape in the previous part?
    4. Estimate an equation for the running time as a function of x.



Dean Foster
Tue Feb 17 10:50:03 EST 1998