n = input('Input the number of copies: ');
u = input('Input the mean: ');
s = input('Input the standard deviation: ');
results = zeros(1,n);
for i = 1:2:n
rsq = -2*log(rand);
theta = 2*pi*rand;
results(i) = s*sqrt(rsq)*cos(theta)+u;
results(i+1) = s*sqrt(rsq)*sin(theta)+u;
end
disp 'Calculated mean and standard deviation using the polar method:';
[mean(results), std(results)]
The program at the end calculates the μ and σ values of the n copies of the random variables created as a result of this simulation, stored in the array named "results."