Approximating Probability using Monte Carlo Method

조회 수: 4 (최근 30일)
khalid alharthi
khalid alharthi 2020년 4월 2일
댓글: khalid alharthi 2020년 4월 2일
I have a problem where I need to sample two random points (x and y) unifromrly from the unit square [0,1] x [0,1]
I need to use the Monte Carlo Method to approximate the probability that (the 2 norm of x-y) ||x-y||_2 is smaller or equal to 1/2
Anyone has an idea on how to go on about this?
  댓글 수: 3
John D'Errico
John D'Errico 2020년 4월 2일
An interesting question is how to compute that result analytically, without recourse to a simulation. Hmm...
'Til then so you can verify your result, I get with a sample size of 1e8 points:
p =
0.48335794
With a predicted standard deviation on that estimate of
s =
4.99722965090615e-05
khalid alharthi
khalid alharthi 2020년 4월 2일
This is what I have, the thing I am not sure about is how to use the Monte Carlo Method to obtain a probability.
for i=1:1000
numPoints = 1000000;
x = rand(numPoints, 1);
y = rand(numPoints, 1);
f = norm(x);
g = norm(y);
Z(i) = abs(f-g);
end
R = Z <= 1/2;
U = R(R==1);
Probability = length(U)/length(R)

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 4월 2일
Hint:
xy = rand(1000000, 2);
or
numPoints = 1000000;
x = rand(numPoints, 1);
y = rand(numPoints, 1);
Look up norm in the help.

카테고리

Help CenterFile Exchange에서 Monte-Carlo에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by