% trigfield11.m displays a trig field using several different scales gridsize = [30 30]; % number of grid points in x, y Z = zeros(gridsize); m = 1000; % number of Fourier modes A = randn(1,m)*sqrt(2/m); % amplitudes of Fourier modes phi = 2 * pi * rand(m,1); % random phase norm = sqrt(-2*log(rand(m,1))); % magnitudes of wave numbers norm = 0.1*((100000).^rand(m,1)); % magnitudes of wave numbers theta = 2 * pi * rand(m,1); % arguments of wave numbers K = [norm.*cos(theta) norm.*sin(theta)]; % isotropic wave numbers a = 0.01; % smallest gridrange b = 5; % zoom factor figure(2) clf for v = 1:9, subplot(3,3,v) gridrange= [0 (a*b^(v-1)) 0 (a*b^(v-1))]; % [xmin xmax ymin ymax] [x,y] = easygrid(gridrange, gridsize); % matrices of x and y values 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 mesh(x,y,Z) view(-10,20) end break figure(1) clf for v = 1:9, subplot(3,3,v) gridrange= [0 (a*b^(v-1)) 0 (a*b^(v-1))]; % [xmin xmax ymin ymax] [x,y] = easygrid(gridrange, gridsize); % matrices of x and y values 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 pcolor(x,y,Z) end