create a program that estimates pi by simulation
2 次查看(过去 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 中查找有关 Monte-Carlo 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!