create a program that estimates pi by simulation

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Leonard Stark
Leonard Stark 2021๋…„ 2์›” 1์ผ
๋‹ต๋ณ€: weikang zhao 2021๋…„ 2์›” 1์ผ
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
Walter Roberson
Walter Roberson 2021๋…„ 2์›” 1์ผ

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

๋‹ต๋ณ€ (1๊ฐœ)

weikang zhao
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.

์นดํ…Œ๊ณ ๋ฆฌ

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!

Translated by