%Clear variables first
clear;
%Define box size
a=2;
b=1;
%Define step size
Da=0.01;
Db=Da;
%Define Vo at left boundary
Vo=1;
%Define box
x=0:Da:a;
y=0:Db:b;
%Use a meshgrid, because it is cool
[X,Y]=meshgrid(x,y);
%Max N
N=50;

%Initialize solution array
V=0.*X;

for n=1:2:N  %Note: Odds only
    
    %Define term n
    Vterm=(4*Vo/(pi)).*(1/n).*exp(-pi*n.*X./b).*sin(pi*n.*Y./b);
    
    %Sum term to existing solution (initial V=0 if n=1)
    V=V+Vterm;
    
    %Plot total solution
    subplot(2,1,1);
    imagesc(X(1,:),Y(:,1),V); 
    axis image;
    colorbar; 
    xlabel('x'); ylabel('y');
    title(['Solution at n=',num2str(n-2)]);
    
    %Plot present term n
    subplot(2,1,2);
    imagesc(X(1,:),Y(:,1),Vterm); 
    axis image;
    colorbar; 
    xlabel('x'); ylabel('y');
    title(['Last Series Term n=',num2str(n-2)]);
    
    %Pause for a keystroke
    pause;

end;
