% MS-E2170 Simulation % Exercise 1.1: Estimate area of a polygon using Monte Carlo simulation % f) Repeat the entire simulation experiment 1000 times using the % worst-case sample size and define the proportion of cases where the % absolute error is less than epsilon = 0.05. % g) Construct 1000 confidence intervals for the estimate of the area and % define their coverage, i.e. the proportion of CI's that contain the % actual value of the area. % % Fill the '' with your own input. % % Created: 2018-02-19 Heikki Puustinen %% Initialization % Sample size (worst-case): N = ; % Number of experiments: M = ; % Define the x- and y-coordinate values of the polygon. px = [0.2, 0.4, 0.8, 0.5]; py = [0, 0.25, 0, 1]; % Define the surrounding rectangle. rx = [0, 0, 1, 1]; ry = [0, 1, 1, 0]; %% Simulation % We now have to call the area estimation function multiple times (once for % each sample size). % Initialize the variables in which we store the results. V = zeros(M,1); Ci = zeros(M,2); % Loop through experiments. for ii = 1:M % Call the area estimation function. [V(ii), Ci(ii,:)] = area_mc(px,py,rx,ry,N); end % Actual area of the polygon. area = polyarea(px,py); % Absolute errors E = ; % Proportion of cases where absolute error < 0.05. P_error = ; % Calculate which CI's include the actual area. D = ; % Calculate the proportion of the experiments where area is included in CI. P_area = ; %% Results % Display results. fprintf('Results f):\n') fprintf('Proportion of cases where absolute error is less than epsilon: %.5f \n', P_error) % Display results. fprintf('Results g):\n') fprintf('Proportion of Ci''s that contain actual area: %.4f \n',P_area)