Advanced Problem Solving A1
Advanced Problem Solving A1
Name ID Number
The core idea of Monte Carlo methods is to replace complex calculations with statistical sampling. By
generating random samples from a defined probability distribution and applying them to the problem at
hand, we can obtain approximate solutions with quantifiable error bounds. The accuracy of these
approximations depends on the number of random samples (N) and the variability (standard deviation) of
the function being sampled.
In this assignment, I explore the application of Monte Carlo methods to three distinct problems:
1. Estimation of π\piπ: A classical problem where random sampling is used to approximate the
value of π\piπ.
2. Single-Dimensional Integration: Using Monte Carlo sampling to evaluate integrals in one
dimension.
3. Multi-Dimensional Integration: Extending Monte Carlo methods to approximate integrals in
higher dimensions.
Furthermore, we conduct a detailed error analysis for these implementations, guided by the theoretical
relationship that the error decreases as ∼ 1/ 𝑁. Through experimental verification, I aim to validate this
theoretical behavior and analyze the impact of factors such as the quality of random number generators,
dimensionality of the problem, and computational trade-offs on the results.
Task 1: Estimation of π Using Monte Carlo Methods
Theory Recap
● Monte Carlo simulation approximates π by estimating the ratio of the area of a circle to the area
of the enclosing square.
● Formula:
Detailed Steps
Python Code
Output
Analysis
Theory Recap
Detailed Steps
2
−𝑥
1. Define the function f(x)= 𝑒 over [0,1].
2. Generate N random samples in [0,1].
3. Compute the integral using the Monte Carlo formula.
2 2
−(𝑥 + 𝑦 )
4. Extend to two dimensions for f(x,y)= 𝑒 over [0,1]×[0,1].
Output
Analysis
Observations:
Key Insights:
● Random Sampling:
○ The fluctuations for small N are due to the randomness of sampling. A small number of
samples may not adequately represent the function's behavior over the integration
domain.
● Stability:
○ Once N exceeds 1000, the integral estimate stabilizes, providing a value very close to the
true result.
● Efficiency:
○ While Monte Carlo integration is simple to implement and works well even for complex
functions, achieving high accuracy requires a large number of samples, especially in
higher dimensions.
Recommendations:
● For higher accuracy in single-dimensional integrations, use N≥10000 for reliable results.
● If computational resources are limited, consider variance reduction techniques (e.g., stratified
sampling or importance sampling) to improve accuracy with fewer samples.
Observations:
Key Insights:
Recommendations:
Verification Steps
1. Calculate the standard deviation (σ) of the sampled function values.
2. Verify error decreases as:
Output
Python Code (Error analysis for 1D integration)
Output
○ The estimates for each N are computed 10 times to get a reliable error estimate.
2. Plotting:
○ The results are visualized on a log-log scale, which is suitable for analyzing power-law
relationships like 1/ 𝑁.
○ The theoretical line (1/ 𝑁) is plotted alongside the experimental results for comparison.
Discussion
1. Quality of Random Number Generators:
○ High-quality random number generators ensure the uniformity of sampled points,
reducing variance in estimates and ensuring proper convergence.
○ Poor-quality generators may introduce biases, leading to higher errors or incorrect
convergence.
2. Trade-offs:
○ Computational Cost: Increasing N reduces error but increases computation time.
○ Accuracy: For applications requiring high precision, larger N is necessary, but
diminishing returns may be observed due to the slow convergence rate (1/ 𝑁).
3. Dimensionality:
○ As dimensionality increases, the integration error converges more slowly due to the
"curse of dimensionality." This explains why the 2D integration error is slightly higher
than the 1D error for the same N.
Conclusion
The experimental results align well with theoretical expectations, verifying that the error for Monte Carlo
methods decreases as 1/ 𝑁. The quality of random number generators and dimensionality significantly
impact the convergence behavior. The trade-off between computational cost and accuracy must be
carefully considered when applying Monte Carlo methods to real-world problems.