Problem 179. Monte-Carlo integration

Write a function that estimates a d-dimensional integral to at least 1% relative precision.


  • d: positive integer. The dimension of the integral.
  • fun: function handle. The function accepts a row-vector of length d as an argument and returns a real scalar as a result.


  • I: is the integral over fun from 0 to 1 in each direction.
     1     1        1            
     /     /        /           
 I = |dx_1 |dx_2 ...| dx_d  fun([x_1,x_2,...,x_d])
     /     /        /            
     0     0        0            


fun = @(x) x(1)*x(2)
d = 2

The result should be 0.25. An output I=0.2501 would be acceptable, because the relative deviation would be abs(0.25-0.2501)/0.25 which is smaller than 1%.

The functions in the test-suite are all positive and generally 'well behaved', i.e. not fluctuating too much. Some of the tests hav a relatively large d.

Solution Stats

32.47% Correct | 67.53% Incorrect
Last solution submitted on Jul 14, 2016

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more