累積平均の求め方を知りたいです
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ビュフォンの針という、円周率をシュミレーションによって求める問題を研究しているmatlab初心者の学生です。
得られた値の累積平均が実際の円周率の値にどのように収束するか調べたいのですが、どのように累積平均を取ればいいのかわかりません。
教えていただきたいです。
N=1000;%針の数
L=0.20;%針の長さ
xb=L+rand(1,N)*(1-2*L);%針の始点のx座標
yb=L*rand(1,N)*(1-2*L);%針の始点のy座標
angs=rand(1,N)*360;%針の傾き
xe=xb+L*cosd(angs);
ye=yb+L*sind(angs);
ax=axes;
plot(ax,[xb;xe],[yb;ye]);%針を表示
axis square
hold on
glines=0:L:1;%平行線を表示
for i =1:length(glines)
xline(ax,glines(i));
end
n=sum(floor(xb/L)~=floor(xe/L));%平行線に交わった針の数
piEstimate=2*N/n%円周率の値を求める
毎回変数を変え、このスクリプトで得られたpiEstimateの値を、実行するたびに今までの値累積平均をとって保存したいと思っています。
方法を教えていただけるとありがたいです。
0 commentaires
Réponse acceptée
Atsushi Ueno
le 30 Oct 2022
piEstAry = []; % 最初に空ベクトルとして初期化しておく
for i = 1:5
piEstAry = [piEstAry, i] % 過去の演算値をベクトルに追記していく
piEstimate = mean(piEstAry) % 平均値を得る
end
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 記述統計と可視化 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
