Monte Carlo Simulation Code
์ด์ ๋๊ธ ํ์
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
Alejandra Bremuantz
2019๋
2์ 14์ผ
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
2020๋
4์ 17์ผ
You need to index hit so that it's a vector.
์ฑํ๋ ๋ต๋ณ
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์นดํ ๊ณ ๋ฆฌ
๋์๋ง ์ผํฐ ๋ฐ File Exchange์์ Monte-Carlo์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!