What is the probability that their children can travel in a straight line between any two points without leaving the boundary? In other words, what is the probability that the boundary is a convex quadrilateral? 

1 visualización (últimos 30 días)
Consider four square shaped ranches arranged in a 2x2 grid. One family lives on each ranch and each family builds a small house independently at a random spot within their property. The families then construct 4 straight line paths between the houses that go across property lines. The path forms a quadrilateral circuit path connecting all four houses which also serves as a boundary in which their children can play. What is the probability that their children can travel in a straight line between any two points without leaving the boundary? In other words, what is the probability that the boundary is a convex quadrilateral? 
This is what I managed to do.
I am struggling to calculate the probability. How do I calculate the probability. Thank you in advance.
P=[0 0; 1 1; 1.5 0.5; 1.5 -0.5; 2 0];
[k,av]=convhull(P);
plot(P(:,1),P(:,2),'*')
hold on
plot(P(k,1),P(k,2))
  2 comentarios
Rik
Rik el 12 de Oct. de 2020
Editada: Rik el 12 de Oct. de 2020
When calculating probability you can do two things:
  1. Directly calculate the probability.
  2. Use a random sample of possible situations and continue sampling until the estimated probability converges to a value.
Which of these two are you trying to do here?
You also forgot to mention that this is homework, so I added the tag for you.

Iniciar sesión para comentar.

Respuestas (2)

Rik
Rik el 12 de Oct. de 2020
If you want to do a Monte-Carlo-style simulation, I would suggest using rand to generate the coordinates. I would suggest putting the center of the four ranches at (0,0), so you can use the sign of either coordinate to easily generate all coordinates.
Given that this is homework: show what you have done to implement this and I might be able to give you some more specific advice.

Image Analyst
Image Analyst el 12 de Oct. de 2020
Isn't is just the solidity? The ratio of the actual area to the convex hullof the area? You can compute that with polyarea(), though I think the Monte Carlo approach would be more fun. Or you could do both and see if my hunch was right or not.
  3 comentarios
Rik
Rik el 12 de Oct. de 2020
Monte Carlo is what I describe in my comment as option 2 (although you will find a more complete description on Wikipedia): just run a ton of simulations and build a probability distribution from the result.
Image Analyst
Image Analyst el 13 de Oct. de 2020
Here is an example of a Monte Carlo simulation:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
fprintf('Beginning to run %s.m ...\n', mfilename);
xy=[-2 -0.25;
0 -0.5;
2 -0.27;
0 -0.35;
-2 -0.25;...
];
plot(xy(:,1), xy(:,2), 'b.-', 'MarkerSize', 40, 'LineWidth', 2)
grid on;
[hullIndexes,av] = convhull(xy);
xyCH = xy(hullIndexes,:)
hold on
plot(xyCH(:,1), xyCH(:,2), 'r-', 'LineWidth', 2)
title('Original in blue, Convex hull in red.', 'FontSize', 20);
numTrials = 4000
originalCount = 0;
numHouses = size(xy, 1);
for k = 1 : numTrials
% Get two random house locations
indexes2 = randperm(numHouses, 2);
% Get xy of first house.
x1 = xy(indexes2(1), 1);
y1 = xy(indexes2(1), 2);
% Get xy of second house.
x2 = xy(indexes2(2), 1);
y2 = xy(indexes2(2), 2);
% Get midpoint of the line.
xMid = mean([x1, x2]);
yMid = mean([y1, y2]);
% See if the midpoint lies inside or outside of the original shape.
% It will be guaranteed to lie within the convex hull so we don't need to check that.
inOriginal = inpolygon(xMid, yMid, xy(:, 1), xy(:, 2));
if inOriginal
% Plot green line.
% plot([x1, x2], [y1, y2], 'g-', 'LineWidth', 2);
originalCount = originalCount + 1;
fprintf('Trial #%d of %d is inside the shape.\n', k, numTrials);
else
% Plot red line.
% plot([x1, x2], [y1, y2], 'r-', 'MarkerSize', 16);
fprintf('Trial #%d of %d is outside the shape.\n', k, numTrials);
end
end
% Get proportion of total trials inside the original shape.
pInShape = originalCount / numTrials
% Get proportion of total trials outside the original shape.
pOutsideShape = (numTrials - originalCount) / numTrials
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m ...\n', mfilename);
You'll get:
pInShape =
0.8105
pOutsideShape =
0.1895

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by