Problem 179. Monte-Carlo integration
Solution Stats
Problem Comments
-
6 Comments
I'm confused by the 3rd test case. Can the integral inside an n-dimensional hypercube really be greater than 1?
In my comment, I mean an n-dimensional UNIT hypercube, which is what you integration limits impose.
Of course. It depends on the integrand. Even in 1d, if the integrand is e.g. 10x, the result will be 5.
I was confused. Thanks for clarifying.
I found it helpful to think about the problem as involving d+1 dimensions: the d dimensions of the input variables, and one more dimension for the (scalar) output variable. —DIV
This problem makes no sense. fun = @(x) x(1)*x(2) needs two inputs. You do not provide enough information for a solution.
Solution Comments
-
1 Comment
Hi sir, could u share ur solution with me cause I attempt nearly 50 times and still ain't got to complate. I don't know where is the problem and it's frustrating.
-
3 Comments
Innovative, but a bit risky/lucky: roughly a 20–30% risk of failing the Test Suite, by my estimation [see Solutions 1572717–1572721, and Solution 1572713; cf. Solution 1572418].
Since the Monte-Carlo errors decrease proportionally to 1/sqrt(N), where N is the number of random numbers, you should always be able to choose a large enough N to nearly always pass the tests. This is only limited by the execution-time limit that cody enforces.
I agree that it is possible to choose N in such a way as to be practically guaranteed to pass the Test Suite. My point is that in this submission (and BTW also in Solution 188645) N has been chosen smaller than that, and so some luck was needed for this submission to pass — there was a significant risk that it could have failed.
-
1 Comment
Nice solution!
-
2 Comments
just found this "cheat". don't hate! I've reported it to TMW
I adjusted the test suite, thanks for the hint...
Problem Recent Solvers54
Suggested Problems
-
Find the two most distant points
2348 Solvers
-
How to find the position of an element in a vector without using the find function
2617 Solvers
-
7845 Solvers
-
431 Solvers
-
681 Solvers
More from this Author7
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!