Monte Carlo Simulation Code

์กฐํšŒ ์ˆ˜: 5 (์ตœ๊ทผ 30์ผ)
Alejandra Bremuantz
Alejandra Bremuantz 2019๋…„ 2์›” 14์ผ
๋Œ“๊ธ€: Image Analyst 2020๋…„ 4์›” 17์ผ
Hello! Can anyone help me out please!!!
I just started using matlab and I have to create a program that caculates the value of pi using the equation ? = ?/ ? 2 . First I need to calculate the value of A within a given radius of 4, and then im given this information: to estimate the area of a circle, we first note that we have a way to determine whether or not a point (x, y) is inside a circle that is centered at the origin and has radius r. Specifically, the distance from the origin to (x, y) is given by: ???????? = โˆš? 2 + ? 2. If this distance is less than or equal to a radius r, then the point (x, y) is within the circle.
My program has to calculate the amount of sqaures that are within the circle because that eqauls the are. Can anyone help??
  ๋Œ“๊ธ€ ์ˆ˜: 3
Yidnekachew A sima
Yidnekachew A sima 2020๋…„ 4์›” 16์ผ
ํŽธ์ง‘: Yidnekachew A sima 2020๋…„ 4์›” 17์ผ
function [estimatepi,c] = estimatepi9(tol)
x=rand;
y=rand;
c=0;
hits=rand;
n= 0;
hit=[];
error=[];
estimatepi=[];
tol=0.0001;
error = abs(pi-estimatepi)-tol;
while error>tol
n=n+1;
x=rand;
y=rand;
hit=(x-0.5).^2+(y.^2)<=1;
for c=1:n;
hits=sum(hit);
estimatepi=4*hits/n;
end
end
end
I am geting un empty set for this file can anyone help?
Image Analyst
Image Analyst 2020๋…„ 4์›” 17์ผ
You need to index hit so that it's a vector.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Image Analyst
Image Analyst 2019๋…„ 2์›” 14์ผ
You need to set x and y to rand(), not zero.
You should know that all Monte Carlo simulations use random numbers, and nowhere in your program do you call rand().
You should also do the loop some number of times, not just once like r==4 would do
for counter = 1 : 10000000 % Try 10 million times.
x = r * rand
y = r * rand
% etc.
% DO NOT increment counter in the loop!
end
  ๋Œ“๊ธ€ ์ˆ˜: 1
Alejandra Bremuantz
Alejandra Bremuantz 2019๋…„ 2์›” 14์ผ
Thank you so much for your respone!
The thing is that the guidelines of the assignment don't let me use a random number generator.
I have to place the center of the circle at the origin so x=0 and y=0 and then set the value of r=4. Only if the distance is equal to or less than the raidus the sqaure is inside of the circle.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Monte-Carlo์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

Community Treasure Hunt

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

Start Hunting!

Translated by