% trigfield5.m investigates the distribution of F(0) m = 20; % number of Fourier modes Cmax = 10000; % number of replications Z = []; % clear the value of Z for C = 1:Cmax, % run through iid replications A = randn(1,m)*sqrt(2/m); % amplitudes A phi = 2 * pi * rand(m,1); % random phase Z(C) = A * cos(phi); % field value at (x,y)=(0,0) end S = sort(Z); % sorted field values p = norminv(((1:Cmax)-0.5)/Cmax); % standard normal percentiles clf % clear the current figure subplot(2,1,1) plot(p,S,'*'); axis([-4 4 -4 4]); title('Normal probability plot'); subplot(2,1,2) hist(S,30); axis([-4 4 0 Cmax/8]); title('Histogram of field values'); fprintf('Z has mean %8.4f and variance %8.4f\n',mean(Z), var(Z))