Skip to content

Instantly share code, notes, and snippets.

@Tejesh-Raut
Last active September 28, 2020 19:13
Show Gist options
  • Save Tejesh-Raut/fa0a308de94065917f370683b9da543e to your computer and use it in GitHub Desktop.
Save Tejesh-Raut/fa0a308de94065917f370683b9da543e to your computer and use it in GitHub Desktop.
Evaluate integral using Monte-Carlo simulation in Python
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