フィルターのクリア

How to estimate pi within a 1x1 square

2 ビュー (過去 30 日間)
Matthew Lozancich
Matthew Lozancich 2017 年 11 月 27 日
コメント済み: Matthew Lozancich 2017 年 11 月 27 日
I was asked to create a function that plots points randomly in a [0,1]x[0,1] square. Then to estimate Pi based on the number of points that fall within the 1st quadrant unit circle.
  • So: points within the unit circle / points total.
  • This should roughly equal pi.I'm stuck on how to create that unit circle boundary and how to look at the # number of points within boundary.This is what I have so far:
function estpi=estimate(npts)
x=zeros(1,npts);
y=zeros(1,npts);
for i=1:npts
x(i)=rand(1);
y(i)=rand(1);
end
plot(x,y,'o')
end
%number of points inside circle/ total points

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 27 日
Remember, inside or on a circle, x^2 + y^2 <= r^2
  1 件のコメント
Matthew Lozancich
Matthew Lozancich 2017 年 11 月 27 日
Thanks for the hint!! figured it out :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by