% Solution to -u_xx-u_yy=1, Double Fourier Sine Series, Animated
% David Bloore, August 2011

nm=input('Maximum number of Sine terms (per x and y)?');
max=2*nm-1;
d=input('Evaluation points per axis?');

[X,Y]=meshgrid(linspace(0,pi,d),linspace(0,pi,d));
Z=zeros(d,d);

ss=surf(X,Y,Z);
title(sprintf('Solution to Poisson Equiation, -u_x_x-u_y_y=1 via Double Sine Series truncated at n,m = %d',max));
xlabel('0 \leq x \leq \pi');
ylabel('0 \leq y \leq \pi');
zlabel('u(x,y)');
set(ss,'EdgeColor','none');
xlim([0 pi]);
ylim([0 pi]);
colorbar('Location','Eastoutside');
set(gcf,'Position',[0 356 1440 900]);
light('Position',[0 -6 6]);

for mm=1:2:max;
    Z=zeros(d,d);
    for n=1:2:mm;
        for m=1:2:mm;
            Z=Z+(16/pi^2)*((sin(m*X)/m).*(sin(n*Y)/n));
        end
    end
    set(ss,'ZData',Z);
    drawnow;
end