Cody

# Problem 179. Monte-Carlo integration

Solution 1840174

Submitted on 5 Jun 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
fun = @(x) x^2; assert(abs((dquad(1,fun) - 1/3)*3)<0.01)

Undefined function 'dquad' for input arguments of type 'function_handle'. Error in Test1 (line 2) assert(abs((dquad(1,fun) - 1/3)*3)<0.01)

2   Fail
fun = @(x) x(1)*x(2); assert(abs((dquad(2,fun) - 0.25)*4)<0.01)

Undefined function 'dquad' for input arguments of type 'function_handle'. Error in Test2 (line 2) assert(abs((dquad(2,fun) - 0.25)*4)<0.01)

3   Fail
fun = @(x) 1+sin(x(1)); assert(abs((dquad(50,fun) - 1.45969769)/1.45969769)<0.01)

Undefined function 'dquad' for input arguments of type 'function_handle'. Error in Test3 (line 2) assert(abs((dquad(50,fun) - 1.45969769)/1.45969769)<0.01)

4   Fail
d = randi([5 10],1) r = rand*0.8 fun = @(x) 2^d*(norm(x)>r); dball = exp(d/2*log(pi)+d*log(r)-gammaln(d/2+1)); assert(abs((dquad(d,fun) - 2^d+dball)/(2^d-dball))<0.01)

d = 8 r = 0.6515

Undefined function 'dquad' for input arguments of type 'function_handle'. Error in Test4 (line 5) assert(abs((dquad(d,fun) - 2^d+dball)/(2^d-dball))<0.01)