Homework 2

  1. Download the files svproc.cls and spbasic.bst. Modify the incomplete TeX file found in Bad.tex according to the specifications detailed in Good.pdf. Replace put your name here with your name, and recreate the plot using data from the PDF file using R. Save your changes as 'Good.tex'.
  2. Practice writing code with the following exercises, avoiding the use of loops and the apply statement. Save your solutions in a file named 'noloops.R' or 'noloops.py':
    • Generate a vector containing integers from 1 to 100 that are not divisible by 2, 3, or 7.
    • Develop a function that takes a matrix or array as input and returns it with the signs of elements between -1 and 1 flipped.
    • Write a function that takes a matrix as input and returns a matrix with each column normalized by subtracting the respective column mean.
  3. Gain practical experience in implementing algorithms and understanding the operations behind built-in functions to simulate random deviates. Develop replacement functions in R ('rdg.R') and Python ('rdg.py') for the following built-in R functions: rnorm, rlnorm, rexp, rpois, rgamma, rchisq, rt, rf, rbeta, rbinom, and rnbinom. Your functions should retain the original argument names and order, returning the same type of output. Only use the runif function in R and the numpy uniform function in Python for random number generation. Refer to this file, Wikipedia, and other web resources for guidance. Note the utilization of methods like the Box-Muller Transformation and the Inverse CDF method in some cases.
  4. Submit your homework by committing the requested files to the appropriate directory (i.e., homework/2) in your central Git repository and pushing the updates.