% Evaluate a wavefunction constructed by the PWDM method.
% CCK 2015-Dec-08 (debug Dec-12)
function psi = wavefunction(xarr, yarr, k, thetas, phases, Coeffs)

N = numel(thetas); % Assumed the same size as phases and Coeffs. Otherwise it could get ugly!
psi = 0*xarr; % Assume that xarr and yarr are the same size. If not, it could get ugly!

for n=1:N
   kx = k * cos(thetas(n)); % Horizontal wavenumber for the nth plane wave. Should be a scalar.
   ky = k * sin(thetas(n)); %   Vertical wavenumber for the nth plane wave. Should be a scalar.
   psi += Coeffs(n) * cos( kx*xarr + ky*yarr + phases(n) );
endfor

