57.2k views
0 votes
Integrate the following integral with the three types of Monte Carlo integration.

I = integrate (sqrt(sin x))/x dx from 0 to 1
First, plot histograms to show the distribution of the two types of random numbers, use 10 ^ 6 many sampling. Then, use 100 sampling of random numbers to estimate I. Repeat this for 50000 times (50000 different estimates of I) to evaluate the standard deviation σ. Plot the estimates of I as histograms (e.g., with plt.hist) for the two types of random numbers specified below.
Define the bins uniformly with keyword argument: bins = np.linspace(np.min(data), np.max(data), 501), where data is either the sampling of random numbers or a list containing the estimates of I. And use plt.vlines to draw two grey vertical lines at x = mu- sigma overline x and x = mu+ sigma overline x where u is the average of the 50000 estimates of I, sigma overline x = sigma/(sqrt(100)) is the standard deviation. You can use a value smaller than 50000 the computation time is too long. And draw a vertical red line to indicate the accurate solution obtained using scipy.integrate.quad. Use (mu - 2sigma, mu + 2sigma) as the range for the x axis.
2.a Use uniform random numbers. From the histogram, does the true value lie between x = mu- sigma overline x and x = mu+ sigma overline x

User Sebi
by
7.6k points

1 Answer

4 votes

Final answer:

To estimate the integral using Monte Carlo integration and uniform random numbers, generate random numbers and calculate the function values. Repeat this process multiple times, calculate the standard deviation, and plot histograms to visualize the estimates. Check if the true value lies within the range.

Step-by-step explanation:

To estimate the integral I = integrate (sqrt(sin x))/x dx from 0 to 1 using Monte Carlo integration and uniform random numbers:

  1. Generate 10^6 uniform random numbers between 0 and 1.
  2. Calculate the function value sqrt(sin x)/x for each random number.
  3. Estimate I by taking the average of the function values.
  4. Repeat steps 1-3 for 50000 times to obtain 50000 different estimates of I.
  5. Calculate the standard deviation σ of the 50000 estimates of I.
  6. Plot histograms of the estimates of I for the two types of random numbers.
  7. Draw two grey vertical lines at x = mu - sigma_overline_x and x = mu + sigma_overline_x, where mu is the average of the estimates of I and sigma_overline_x = sigma / sqrt(100).
  8. Draw a vertical red line to indicate the accurate solution obtained using scipy.integrate.quad.

From the histogram, check whether the true value lies between x = mu - sigma_overline_x and x = mu + sigma_overline_x.

User Florian Courtial
by
8.4k points