Last active
September 28, 2020 19:13
-
-
Save Tejesh-Raut/fa0a308de94065917f370683b9da543e to your computer and use it in GitHub Desktop.
Evaluate integral using Monte-Carlo simulation in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import uniform | |
np.random.seed(0) | |
mcos_estimates = [None]*50 | |
mcos_std = [None]*50 | |
for i in range(1,51): | |
unif_array = uniform.rvs(size = i*1000)*2 | |
cos_val = np.cos(unif_array)*2 | |
mcos_estimates[i-1] = np.mean(cos_val) | |
mcos_std[i-1] = np.std(cos_val)/np.sqrt(i*1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment