%% Monte Carlo integration % This code lets you approximate the area under the graph of x^2 for x % between 0 and 1, so the integral of x^2 from 0 to 1 by choosing n random % points in the unit square and calculating the fraction of points which % are under the graph. The notation x.^2 means square each component of the % vector x. n = 10000; % set the value of n x = rand(1,n); % choose n random x values y = rand(1,n); % choose n random y values sum(y