f = @(x) x.^2;
sol = 1/3;


a = 0;
b = 1;

N = round(logspace(2,5,11));
M = length(N);
error_v = zeros(M,1);
K = 500;

for i = 1:M
    I = 0;
    error_k = zeros(K,1);
    for k = 1:K
        error_k(k) =  abs(mc2(f,a,b,N(i))-sol);
    end
    
    error_v(i) = mean(error_k);
end
%%
figure(1)
loglog(N,error_v,'-')
hold on
loglog(N,1./sqrt(N),'--')
hold off