% Delta Function(x,y), Truncated Double Cosine Series
% David Bloore, August 2011

% 7,190;
% 15, 150, 1/4
% 30, 300, 1/4

nm=input('Number of Sine terms (per x and y)?');
d=input('Evaluation points per axis?');
ll=0.25;
dl=ll*pi;
[X,Y]=meshgrid(linspace(-dl,dl,d),linspace(-dl,dl,d));
Z=zeros(d,d)+(1/(2*pi)^2);

for m=1:nm;
    Z=Z+(1/(2*pi^2))*(cos(m*X));
end

for n=1:nm;
    Z=Z+(1/(2*pi^2))*(cos(n*Y));
end

for n=1:nm;
    for m=1:nm;
        Z=Z+(1/pi^2)*((cos(m*X)).*(cos(n*Y)));
    end
end

ss=surf(X,Y,Z);
title(sprintf('Delta Function(x,y), Truncated Double Cosine Series, up to n,m=%d',nm));
xlabel([sprintf('%d',-ll) '*\pi \leq x \leq ' sprintf('%d',ll) '*\pi']);
ylabel([sprintf('%d',-ll) '*\pi \leq y \leq ' sprintf('%d',ll) '*\pi']);
zlabel('u(x,y)');
set(ss,'EdgeColor','none');
xlim([-dl dl]);
ylim([-dl dl]);
colorbar('Location','Eastoutside');
set(gcf,'Position',[0 356 1440 900]);
view([-37.5 22.0]);
light('Position',[0 -1 6]);