% MS-E2170 Simulation % Exercise 1.1: Estimate area of a polygon using Monte Carlo simulation % b) What is your estimate for the area of P? Define a 1-delta confidence % interval for the estimate with delta = 0.05. % c) Compare your solution to the actual area of the polygon. % % Fill the '' with your own input. % % Created: 2018-02-19 Heikki Puustinen %% Initialization % Sample size: N = ; % 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 use the area estimation function area_mc. % V = estimated area % Ci = confidence interval [lower, upper] [V, Ci] = area_mc(); %% Results fprintf('Results:\n') % Actual area of the polygon. area = polyarea(px,py); % Display estimated area (%.5f = float with 5 digits after the % decimal point). You can also use 'display' function. fprintf('Estimated area: %.5f \n', V) % Display confidence intervals fprintf('Confidence interval: [%.5f, %.5f]\n', Ci(1),Ci(2)) % Display actual area fprintf('Actual area: %.5f \n',area)