% trigfield7.m allows you to explicitly choose wavenumbers gridsize = [80 80]; % number of grid points in x, y gridrange= [0 15 0 15]; % default [xmin xmax ymin ymax] [x,y] = easygrid(gridrange, gridsize); % matrices of x and y values Z = []; K = [[2 0]; [0 1]; [1 1]]; % wave numbers K = [[1 0]; [0 1]; [-1 0]; [0 -1]]; mm=100; K = [cos(2*pi*(0:mm)/mm)' sin(2*pi*(0:mm)/mm)']; m = length(K(:,1)); % number of modes A = randn(1,m)*sqrt(2/m); % amplitudes of Fourier modes phi = 2 * pi * rand(m,1); % random phase for i=1:gridsize(1), % step through grid points for j=1:gridsize(2), Z(i,j) = A * cos(K*[x(i,j); y(i,j)] + phi); % compute field value at x,y end end subplot(3,2,1) mesh(x,y,Z) view(-10,30) xlabel('Horizontal'); ylabel('Vertical'); zlabel('Intensity'); title('Surface plot'); subplot(3,2,2) pcolor(x,y,Z>0) shading flat title('Level sets') subplot(3,2,3) contour(x,y,Z,20) title('Contour plot') subplot(3,2,4) pcolor(x,y,Z) shading flat title('Intensity plot') subplot(3,2,5) hist(reshape(Z,1,gridsize(1)*gridsize(2))) title('Histogram of field values') subplot(3,2,6) plot(K(:,1),K(:,2),'*') maxcoord = max(max(abs(K))); axis([-maxcoord maxcoord -maxcoord maxcoord]); title('Wavenumbers K')