⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c9_estimatepi.m

📁 pi的蒙特卡罗估计 matlab源程序有5个pi的估计
💻 M
字号:
% File: c9_estimatepi
% Software given here is to accompany the textbook: W.H. Tranter, 
% K.S. Shanmugan, T.S. Rappaport, and K.S. Kosbar, Principles of 
% Communication Systems Simulation with Wireless Applications, 
% Prentice Hall PTR, 2004.
%
m=input('Enter M, the number of experiments > ');
n=input('Enter N, the number of trials per experiment > ');
 z=zeros(1,m);
data = zeros(n,m);
for j=1:m
    x=rand(1,n);
    y=rand(1,n);
    k=0;
    for i=1:n
        if x(i)^2+y(i)^2 <= 1		% Fall inside pie slice?
            k=k+1;
        end
        data(i,j) = 4*(k/i);		% jth estimate of pi
    end
    z(j) = data(n,j);				% Store data
end
plot(data,'r')						% Plot curves
xlabel('Number of Trials')
ylabel('Estimate of pi')
% End of script file.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -