Implement Monte Carlo integration on a GPU. Given a set of function values \(y_i = f(x_i)\) sampled at random points \(x_i\) uniformly distributed in the interval \([a, b]\), estimate the definite integral: \[ \int_a^b f(x) \, dx \approx (b - a) \cdot \frac{1}{n} \sum_{i=1}^{n} y_i \] The Monte Carlo method approximates the integral by computing the average of the function values and multiplying by the interval width.
solve function signature must remain unchangedresult variable
Input: a = 0, b = 2, n_samples = 8
y_samples = [0.0625, 0.25, 0.5625, 1.0, 1.5625, 2.25, 3.0625, 4.0]
Output: result = 3.1875
n_samples ≤ 100,000,000a < b ≤ 1000.0n_samples = 10,000,000