程序代写 practice – Problem 1

practice – Problem 1

Copyright By PowCoder代写 加微信 powcoder

import numpy as np
from scipy.stats import uniform

## record your uni here

Problem 1 (25 points)¶
Let $$\theta = \int_0^1 \int_0^y \exp(-x^2) x^4 dx dy$$

Use the monte carlo method to estimate $\theta$.

np.random.seed(42)
n = 10_000

U = uniform.rvs(size=(n,2))

f = np.exp(-U[:,0]**2) * (U[:,0] ** 4)
loc = U[:,0] > U[:,1]
f[loc] = 0

theta = np.mean(f)
print(theta)

0.008551462974661273

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com