Homework 4

CHE 116: Numerical Methods and Statistics

(2/7/2019)


1. Lists and Arrays (20 Points)

  1. [2 points] Make a list of integers ranging from 0 to 100 in reverse order in increments of 2.

  2. [2 points] Modify the above list to have "Happy" as the 45th element and the word "Friday" as the last element.

  3. [2 points] Append 20 more integers ranging from 6 to 26, in increments of one, to the previous list.

  4. [3 points] What is the mean of the first quarter of the resulting list. Use sum and the len of the list to compute which index corresponds to the quarter.

  5. [5 points] Repeat problem 4 using a for loop.

  6. [3 points] Create 100 by 3 array of integers ranging from 0 to 300, not including 300 with increment of one in ascending order. Use numpy and not a for loop. Hint: try using numpy.reshape() function. The answer should be something like this:

    [[0 1 2]
    [3 4 5]
    [6 7 8]
    ......
    [291 292 293]
    [294 295 296]
    [297 298 299]]

  7. [3 points] Find $\cos(x)$ where $x = $ [0, $\pi$] with 400 elements.

2. Plotting with Python (8 Points)

  1. [2 points] Plot $\sin(x)$ where x is years ranging from 1998 to 2018 biannually.

  2. [3 points] In a different plot, plot $\sin(x)$, $\cos(x)$, $\sin(2x)$, and $\cos(2x)$ over the domain of $[-\pi,\pi]$ in increments of 0.1 radians. Colors for $\sin(x)$, $\cos(x)$, $\sin(2x)$, and $\cos(2x)$ should be red, blue, yellow and green, respectively.

  3. [3 points] Make a plot of $\sin(x)$ ranging from (-$\pi$,$\pi$) with 4 data points, with 6 data points, with 8 data points and with 32 data points. Label plots with red, blue, green, and yellow colors for 4,8,16 and 32 points-containing plots.

3. Expected Value and Variance (13 Points)

  1. [3 points] For multiple generations, adults in Robertons family had 4 hieghts: 195cm, 180cm, 168cm, and 170cm with probablities of 0.2, 0.3, 0.1, and 0.4, respectively. What are expected height and the variance of the heights for adults in Robertson family?

  2. [3 points] Looking at historic data from Organic Chemistry course at University of Rochester, it was found that students were given the following grades, 100%, 95%, 80%, 75%, 70% and 65% with the following probabilites, 0.1,0.2,0.4,0.3, and 0.2 respectively. What is the expected value of a grade in organic chemistry class.

  1. [3 points] The unormalized probability distribution funciont of position, $x$, on [-2,2] is given by $-x^2+4$. What is the expected value of position $x$ in [-2,2]. Remember to normalize the probablity.

  2. [3 points] You are rolling an unfair dice. The probabilities of getting 6, 5, 4, 3, 2, and 1 are the following: 0.3, 0.25, 0.1, 0.1, 0.2, and 0.05. What is the expected value of rolling an unfair dice?

  3. [1 point] Your are thinking of investing in company that flips coin to determine whether you make a profit or do not make a profit. If the coin is heads, you make profit of 4 dollars and if the coin is tails, you lose 2 dollars. What is expected value of gaining/losing in this game?