create a program that estimates pi by simulation
์กฐํ ์: 1 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Create a program that estimates pi (๐) by simulation. This is accomplished by drawing random points in a unit square (1x1), and counting which ones fall inside a quarter of a unit circle (radius=1). The value of pi is then estimated using the ratio of areas of the quarter circle to the unit square. Calculate estimates of pi and relative error for 100, 1000, 10000, 100000 and 1000000 samples.
๋ต๋ณ (1๊ฐ)
weikang zhao
2021๋
2์ 1์ผ
This seems to be your homework and not a technical problem. Normally, I donโt do homework for others, but this question is simple enough.
N=100000;
pi_est=4*sum((unifrnd(0,1,N,1).^2+unifrnd(0,1,N,1).^2)<=1)/N;
change N to get all the estimates you want.
๋๊ธ ์: 0
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Pulse and Transition Metrics์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!