A1 Excercise 1

Suppose \(f(x) = xe^x\), find f’(x).

\[ f'(x) = e^x + xe^x \]

A1 Excercise 2

Suppose \(f(x) = e^{2x}\), find f’(x).

\[ f(x) = g(h(x)), \hspace{0.5cm} where \hspace{0.3cm} h(x) = 2x, g(x) = e^x \\ f'(x) = 2e^{2x} \]

A1 Excercise 3

Derive \(\int f'(x)g(x) \, dx = f(x)g(x) - \int f(x)g(x)' \, dx\).

\[ (f(x)g(x))'= f'(x)g(x) + f(x)g'(x) \\ f'(x)g(x) = \frac{d}{dx}(f(x)g(x)) - f(x)g'(x) \\ \int f'(x)g(x)' \, dx = f(x)g(x) - \int f(x)g(x)' \, dx \]

A1 Excercise 4

Find \(\int xe^x \, dx\), and evaluate \(\int_{0}^{1} xe^x \, dx\). \[ \frac{d}{dx}(xe^x) = e^x + xe^x \\ xe^x = \frac{d}{dx}(xe^x) - e^x \\ \int xe^x \, dx = xe^x - e^x + C \]

A1 Excercise 5

Write a python code that does the exactly same thing as the above code block.

def f(x):
    return 1 + 1/x

tol = 10**(-5)
x_now = 0.1

while True:
    x_next = f(x_now)
    if abs(x_next - x_now) < tol:
        break
    x_now = x_next
    print(x_next)

A1 Excercise 6

Solve the followings.

\[ \begin{pmatrix} .6 & .4 \end{pmatrix} \begin{pmatrix} .7 & .3 \\ .5 & .5 \end{pmatrix}= \begin{pmatrix} .42 + . 20 & .18 + .20 \end{pmatrix} \]

A1 Excercise 7

What is \(P^2\)?

\[ P^2= \begin{pmatrix} .49+.15 & .21+.15 \\ .35+.25 & .15+.25 \end{pmatrix} \]

A1 Excercise 8

Solve the followings.

\[ \begin{pmatrix} V_1 & V_2 \end{pmatrix} \begin{pmatrix} .7 & .3 \\ .5 & .5 \end{pmatrix}= \begin{pmatrix} V_1 & V_2 \end{pmatrix} \\ V_1 + V_2 = 1 \\ \\ V_1 = \frac{5}{8}, V_2 = \frac{3}{8} \]

A1 Excercise 8

Solve the followings.

\[ \begin{pmatrix} V_1 & V_2 \end{pmatrix} \begin{pmatrix} .7 & .3 \\ .5 & .5 \end{pmatrix}= \begin{pmatrix} V_1 & V_2 \end{pmatrix} \\ V_1 + V_2 = 1 \\ \\ V_1 = \frac{5}{8}, V_2 = \frac{3}{8} \]

A1 Excercise 9

Solve the following system of equations.

\[ x = y \\ y = 0.5z \\ z = 0.6 - 0.4x\\ x + y + z = 1 \\ \\ x = 0.25, y = 0.25, z = 0.5 \]

A1 Excercise 10

Solve the following system of equations.

\[ \begin{pmatrix} V_0 & V_1 & V_2 \end{pmatrix} \begin{pmatrix} -2 & 2 & 0 \\ 3 & -5 & 2 \\ 0 & 3 & -3 \end{pmatrix}= \begin{pmatrix} 0 & 0 & 0 \end{pmatrix} \\ V_0 + V_1 + V_2 = 1 \\ \\ V_0 = \frac{9}{19}, V_2 = \frac{6}{19}, V_3 = \frac{4}{19} \]

A1 Excercise 11

Solve the following system of equations.

\[ \begin{pmatrix} V_1 & V_2 & V_3 & V_4 \end{pmatrix} \begin{pmatrix} .7 & .3 & 0 & 0 \\ .5 & .5 & 0 & 0 \\ 0 & 0 & .6 & .4 \\ 0 & 0 & .3 & .7 \end{pmatrix} = \begin{pmatrix} V_1 & V_2 & V_3 & V_4 \end{pmatrix} \\ V_1 + V_2 + V_3 + V_4 = 1 \\ V_1 + V_2 = a \\ \\ \\ V_1 = \frac{5}{8}a, V_2 = \frac{3}{8}a, V_3 = \frac{3}{7}(1-a), V_4 = \frac{4}{7}(1-a) \]

A1 Excercise 12

Solve the following and express \(V_i \hspace{0.3cm} for \hspace{0.1cm} i=0,1,2, ...\).

\[ V_0 + V_1 + V_2 + ... = 1 \\ 0.02V_0 + 0.02_V1 + 0,02V_2 + ... = V_0 \\ 0.98V_0 = V_1 \\ 0.98V_1 = V_2 \\ 0.98V_2 = V_3 \\ ... = ... \\ \\ \\ V_2 = 0.98^2V_0, V_3 = 0.98^3V_0, ...\\ V_i = 0.98^iV_0 \]

A1 Excercise 13

Simplify the following. When \(|r|<1, \hspace{0.3cm} S=a+a+ar+ar^2+ar^3+...\).

\[ S=a+ar+ar^2+ar^3+ ... \\ rS = ar + ar^2 +ar^3 + ... \\ \\ = (1-r)S = a = \frac{a}{1-r} \]

A1 Excercise 14

Simplify the following. When \(|r| != 1, \hspace{0.3cm} S=a+a+ar+ar^2+ar^3+...+ar^{n-1}\).

\[ S=a+ar+ar^2+ar^3+ ... + ar^{n-1}\\ rS = ar + ar^2 +ar^3 + ... + ar^n\\ \\ = (1-r)S = a +ar^n = a\frac{1-r^n}{1-r} \]

A1 Excercise 15

Simplify the following. When \(|r| < 1, \hspace{0.3cm} S= r + 2r^2 + 3r^3 + 4r^4 + ...\).

\[ S= r+2r^2+3r^3+ ... \\ rS= r^2+2r^3+3r^4+ ... \\ \\ = (1-r)S = r+r^2+r^3 + ... = \frac{4}{(1-r)^2} \]

A1 Excercise 16

During the first hour \((0 <= t <= 1), \lambda(t)\) increases linearly from 0 to 60. After the first hour \(\lambda(t)\) is constant at 60. Draw plot for \(\lambda(t)\) and express the function in math form.

\[ \lambda(t) = \begin{cases} 60t & \text{if } 0 \leq t \leq 1 \\ 60 & \text{if } t > 1 \end{cases} \]

t <- seq(0, 2, by = 0.01)
lambda_t <- ifelse(t <= 1, 60 * t, 60)
data <- data.frame(t = t, lambda_t = lambda_t)
ggplot(data, aes(x = t, y = lambda_t)) +
  geom_line(color = "blue") +
  labs(title = "Plot of λ(t)", x = "t", y = "λ(t)") +
  theme_minimal()

A2 Excercise 1

Show that \(P(A|B \cap C)P(B|C) = P(A\cap B|C)\).

\[ P(A|B \cap C) = \frac{P(A \cap (B \cap C))}{P(B \cap C)}, P(B|C) = \frac{P(B \cap C)}{P(C)} \\ P(A|B \cap C) \cdot P(B|C) = \left( \frac{P(A \cap (B \cap C))}{P(B \cap C)} \right) \cdot \left( \frac{P(B \cap C)}{P(C)} \right) = \frac{P(A \cap B \cap C)}{P(C)} \\ \\ P(A \cap B|C) = \frac{P(A \cap B \cap C)}{P(C)}\\ P(A|B \cap C)P(B|C) = P(A \cap B|C) \]

A2 Excercise 2

Prove that \(pdf \rightarrow cdf\).

A2 Excercise 3

\(X \sim U(10, 20)\), then what is \(F(10)\) and \(F(15)\)? \[ 1. (x<0), \\ F(x) = \int_{-\infty}^{x} f(t) \, dt = 0, F(x) = 0 \\ 2. (x >- 0), \\ F(x) = \int_{0}^{x} \lambda e^{-\lambda t} \, dt = 0 + \lambda e^{-\lambda x} dx ... = 1- \lambda e^{-\lambda x} \]

A2 Excercise 4

Show that \(EX = 1/\lambda\)

A2 Excercise 5

Show that \(Var(X) = 1/\lambda^2\)

A2 Excercise 6

Prove the previous theorem.

A2 Excercise 7

For \(X \sim Poi(\lambda),\) prove that \(EX = \lambda\).

A2 Excercise 8

Prove the above theorem.

A2 Excercise 9

For \(X \sim U(20, 40)\), evaluate $E[X ]$ and \(E[(25 - X)^+\).

A2 Excercise 10

For \(X \sim Poi(8)\), \[ P(X=0) = \frac{8e^-8}{0} \\ P(2<= X <= 4) = \\ P(X > 2) = \\ \]

A2 Excercise 11

For \(X \sim exp(7)\), evaluate \(E[max(X, 7)]\). \[ E[max(X, 7)] = \int_{-\infty}^{\infty} max(X, 7)f(x) \, dx\\ = \int_{-\infty}^{0} max(X, 7)f(x) \, dx + \int_{7}^{\infty} max(X, 7)f(x) \, dx\\ = \int_{-\infty}^{0} max(X, 7)7e^{-7x} \, dx + \int_{7}^{\infty} max(X, 7)7e^{-7x} \, dx\\ = \int_{-\infty}^{0} 7 \times 7e^{-7x} \, dx + \int_{7}^{\infty} x7e^{-7x} \, dx\\ \]

A2 Excercise 12

For \(X \sim exp(8)\), find \(x^*\) such that \(F(x^*) = 0.6\).

A2 Excercise 13

For \(X \sim U(10, 20)\), find \(x^*\) such that \(F(x^*) = 0.7\).

TODO: A2 and A3 excercise

A3 Excercise 1

  1. Is \(\bar{X}\) an unbiased estimator for \(\mu\), why or why not? Yes
  2. Is \(\bar{X}\) a consistent estimator for \(\mu\), why or why not? Yes
  3. Is \(\bar{X}\) a ML estimator for \(\mu\), why or why not? Yes

A3 Excercise 2

You randomly sample 1,600 Korean male and measured their hand length. The sample mean is 20cm and the sample standard deviation is 2cm. What is the 95% confidence interval for Korean male’s hand length?

\[ N = 1600, \mu = 20, \sigma = 2 \\ \frac{2}{\sqrt{1600}} = \frac{2}{40} = 0.05 \\ ME = z \times SE = 1.96 \times 0.05 = 0.098 \\ \bar{x} \pm ME = 20 \pm 0.098\\ (19.902, 20.098) \]

A4 Excercise 1

Write the two programs in the previous page with python and compare the computation time.

import time
import numpy as np

beg_time = time.time()
np.random.seed(1234)
MC_N = 10**6
x = np.random.uniform(-1, 1, MC_N)
y = np.random.uniform(-1, 1, MC_N)
t = np.sqrt(x**2 + y**2)
pi_hat = 4 * np.sum(t <= 1) / MC_N
end_time = time.time()
print(end_time - beg_time)
print(pi_hat)

beg_time = time.time()
np.random.seed(1234)
MC_N = 10**6
count = 0

for _ in range(MC_N):
    x_i = np.random.uniform(-1, 1)
    y_i = np.random.uniform(-1, 1)
    t_i = np.sqrt(x_i**2 + y_i**2)
    if t_i <= 1:
        count += 1

pi_hat = 4 * count / MC_N
end_time = time.time()
print(end_time - beg_time)
print(pi_hat)

A4 Excercise 2

Do the above experiment with MC_N increased by the factor of ten, and present the confidence interval. (Use set.seed(1234))

pi_simulator3 <- function(MC_N) { # name change
  # set.seed(1234) # seed must not be fixed
  x <- runif(MC_N)* 2-1
  y <- runif(MC_N)* 2-1
  t <- sqrt(x^2+y^2)
  pi_hat <- 4*sum(t<=1)/MC_N
  return(pi_hat)
}


n <- 100
MC_N <- 10000
set.seed(1234)
samples <- rep(0, n)
for (i in 1:n) {
  samples[i] <- pi_simulator3(MC_N)
}
X_bar <- mean(samples)
s <- sqrt(sum((X_bar - -samples)^2)/(n-1))
t <- qt(p=0.975, df =  n-1)
lb <- X_bar - t*s/sqrt(n) # lower bound
ub <- X_bar+t*s/sqrt(n) # upper bound
lb

A4 Excercise 3

Do the above experiment with MC_N increased by the factor of ten, and present the confidence interval. (Use set.seed(1234))

pi_simulator3 <- function(MC_N) { # name change
  # set.seed(1234) # seed must not be fixed
  x <- runif(MC_N)* 2-1
  y <- runif(MC_N)* 2-1
  t <- sqrt(x^2+y^2)
  pi_hat <- 4*sum(t<=1)/MC_N
  return(pi_hat)
}


n <- 1000
MC_N <- 10000
set.seed(1234)
samples <- rep(0, n)
for (i in 1:n) {
  samples[i] <- pi_simulator3(MC_N)
}
X_bar <- mean(samples)
s <- sqrt(sum((X_bar - -samples)^2)/(n-1))
t <- qt(p=0.975, df =  n-1)
lb <- X_bar - t*s/sqrt(n) # lower bound
ub <- X_bar+t*s/sqrt(n) # upper bound
lb

A4 Excercise 4

Present a previous page’s table by writing a neat python code block.

import numpy as np
from scipy.stats import t

def pi_simulator3(MC_N):
    x = np.random.uniform(-1, 1, MC_N)
    y = np.random.uniform(-1, 1, MC_N)
    t = np.sqrt(x**2 + y**2)
    pi_hat = 4 * np.sum(t <= 1) / MC_N
    return pi_hat

n = 1000
MC_N = 10000
np.random.seed(1234)
samples = np.zeros(n)
for i in range(n):
    samples[i] = pi_simulator3(MC_N)

X_bar = np.mean(samples)
s = np.sqrt(np.sum((samples - X_bar)**2) / (n - 1))
t_value = t.ppf(0.975, df=n-1)
lb = X_bar - t_value * s / np.sqrt(n)
ub = X_bar + t_value * s / np.sqrt(n)

print(lb)
print(ub)

A5 Excercise 1

N <- 1000
u <- runif(N)
x <- -1 / 3 * log(1 - u)
head(x)
## [1] 0.48139092 0.18200038 0.01487347 0.13916898 0.09733630 0.45562079

A5 Excercise 2

import numpy as np
import matplotlib.pyplot as plt

X = np.random.uniform(-1, 1, 1000)
plt.hist(X, bins=30, edgecolor='black')
plt.show()

X = np.random.normal(3, 2, 1000)
plt.hist(X, bins=30, edgecolor='black')
plt.show()

X = np.random.exponential(5, 10000)
plt.hist(X, bins=20, edgecolor='black')
plt.show()

X = np.random.poisson(5, 10000)
plt.hist(X, bins=20, edgecolor='black')
plt.show()