フィルターのクリア

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 件)

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 ExchangePulse and Transition Metrics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by