c9_example5.m

来自「很多MATLAB的无线系统仿真实例。强烈推荐!」· M 代码 · 共 24 行

M
24
字号
% File: c9_example5
% 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=5;						% Number of experiments
N=500;					    % Trials per experiment
u = rand(N,M);	    		% Generate random numbers
uu = 1./(1+u.*u);		    % Define function
data = zeros(N,M);	        % Initialize array
% The following four lines of code determine
% M estimates as a function of j, 0<j<=N.
data(1,:) = 4*uu(1,:); 
for j=2:N
   data(j,:)=4*sum(uu(1:j,:))/j;
end
est = data(N,:)		        % M estimates of pi
est1 = sum(est)/M		    % Average estimate
plot(data,'k')			    % Plot results
xlabel('Number of Trials')
ylabel('Estimate of pi')
% End of script file.

⌨️ 快捷键说明

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