% trigfield8.m generates field values at random locations numpoints= 100; x = 5*randn(numpoints,1); y = 5*rand(numpoints,1); Z = zeros(numpoints,1); m = 100; % 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 theta = 2 * pi * rand(m,1); % arguments of wave numbers K = [norm.*cos(theta) norm.*sin(theta)]; % isotropic wave numbers for i=1:numpoints, Z(i) = A * cos(K*[x(i); y(i)] + phi); % compute field value at x,y end figure(1) clf subplot(2,1,1) plot(x,y,'*'); axis([min(x) max(x) min(y) max(y)]); title('Locations at which the field is sampled'); subplot(2,1,2) tag3(x,y,Z) view(-10,30) title('Data points in 3d') rotate3d on