%% Ncossinmat2 %% function that returns the matrix to produce "Fourier" cosine-sine coefficients %% this function is the same as Ncossinmat except the calculation is vectorized function A = Ncossinmat2(N) % test of even or odd % even = 1 if N is even and even =0 if N is odd. Note the use of ~. even = ~rem(N,2); n = fix((N-1)/2); %Construct column vector of sample points. Note the use of ' t = (2*pi/N)*(0:1:(N-1))'; % the following loops use vectorized function evaluation % the matrix is created column by column A = ones(N,1); for j = 1:n A = [A,cos(j*t)]; end; if even A = [A, cos((N/2)*t)]; end; % add in extra column of cosines for even N for j = 1:n A = [A,sin(j*t)]; end;