% trigfield2A.m turns an evolving trig field into a movie gridsize = [40 40]; [x,y] = easygrid([0 15 0 15], gridsize); % [xmin xmax ymin ymax] clear Zm m = 10; % number of 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 theta = 2 * pi * rand(m,1); % arguments of wave numbers K = [norm.*cos(theta) norm.*sin(theta)]; % isotropic wave numbers for C=1:30, for i=1:gridsize(1), % step through grid points for j=1:gridsize(2), Zm(i,j,1,C) = A * cos(K*[x(i,j); y(i,j)] + phi); % compute field value at x,y end end A = cos(.1)*A + sin(.1)*randn(1,m)*sqrt(2/m); % small change in A; variances sum to 1 end mi = min(min(min(Zm))); ma = max(max(max(Zm))); Zm = (Zm-mi)*length(jet)/(ma-mi); % scale Z values to run from 0 to % number of rows in the colormap jet clf mov = immovie(Zm,jet); % paste Zm values into a movie movie(mov,3); % cycle through the movie 3 times