MATLAB: For the same answer,,suppose, X ranges from 1 to 500, y ranges from 1 to 200 , Is it possible to find how many such coordinates are possible so that distance from each and every coordinate to other coordinate is > 20

homeworkmonte carlo experiment

BWremain = true(300);
% Number of random coordinates
N = 100;
% Selected coordinates are stored these variables
row = nan(N,1);
col = nan(N,1);
for kk = 1:N
BW = false(300);
p = find(BWremain);
p = p(randperm(numel(p),1));
BW(p) = true;
BW = bwdist(BW) > 20;
BWremain = BWremain & BW;
[row(kk),col(kk)] = ind2sub(size(BWremain),p)
end

Best Answer

The max number varies depending on what points were actually placed. Using numbers from your question, and trying a million coordinates, we can see that we can place from about 150 to 200 points. See code below:
pointsToPlace = 5000000 ; % # of random coordinates we need to place - some huge number
% Preallocate points
x = zeros(1, pointsToPlace);
y = zeros(1, pointsToPlace);
loopCounter = 1;
maxIterations = 1000000; % Number of tries before giving up.
numberPlaced = 0; % No points placed yet.
while numberPlaced < pointsToPlace && loopCounter <= maxIterations
% Get new coordinate
xProposed = 1 + (500-1)*rand(); %% random X- coordinates
yProposed = 1 + (200-1)*rand(); %% random Y- coordinates
if loopCounter == 1
% First one automatically gets added of course.
numberPlaced = 1;
x(numberPlaced) = xProposed;
y(numberPlaced) = yProposed;
else
% Compute distance to all prior coordinates.
distances = sqrt((xProposed - x(1:numberPlaced)) .^ 2 + (yProposed - y(1:numberPlaced)) .^2);
% If less than 20, add it
if min(distances > 20)
numberPlaced = numberPlaced + 1;
x(numberPlaced) = xProposed;
y(numberPlaced) = yProposed;
end
end
loopCounter = loopCounter + 1;
end
% Crop to how many we actually got.
x = x(1:numberPlaced);
y = y(1:numberPlaced);
fprintf('Placed %d points after %d iterations\n', numberPlaced, loopCounter-1);
plot(x, y, 'b*', 'LineWidth', 2, 'MarkerSize', 14);
grid on;
axis equal
xlim([0, 500]);
ylim([0, 200]);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
0001 Screenshot.png
I'm not aware of an analytical statistical answer, so above we solve it numerically.