format compact;
a = 5;	
H = pi/2; 
NptsR=151;          % number of x pts
NptsTH=151;          % number of t pts
Nf=150;              % number of Fourier terms
r=linspace(0,a,NptsR);
t=linspace(0,H,NptsTH);
[R,TH]=ndgrid(r,t);

fs=8;
figure(1)
clf

b=zeros(1,Nf);
U=zeros(NptsTH,NptsR);

for n=1:Nf
    if (mod(n,4)==1)
       b(n)=2.23754/((2*n-1)*5^(2*n-1));  % Fourier coefficients
    elseif (mod(n,4)==2)
       b(n)=-13.0413/((2*n-1)*5^(2*n-1));  % Fourier coefficients
    elseif (mod(n,4)==3)
       b(n)=13.0413/((2*n-1)*5^(2*n-1));  % Fourier coefficients
    else 
       b(n)=-2.23754/((2*n-1)*5^(2*n-1));  % Fourier coefficients
    end
    Un=b(n)*(R.^(2*n-1)).*cos((2*n-1)*TH);  % Temperature(n)
    U=U+Un;
end

set(gca,'FontSize',[fs]);
[R,TH] = pol2cart(TH,R);
surf(R,TH,U);
shading interp
colormap(jet)
fontlabs = 'Times New Roman';
xlabel('$x$','Fontsize',fs,'FontName',fontlabs,'interpreter','latex'); 
ylabel('$y$','Fontsize',fs,'FontName',fontlabs,'interpreter','latex'); 
zlabel('$u(x,y)$','Fontsize',fs,'FontName',fontlabs,'interpreter','latex'); 
%axis tight
colorbar
view([40 20])
print -depsc WW6_a.eps

figure(2)
clf

set(gca,'FontSize',[fs]);
surf(R,TH,U);
shading interp
colormap(jet)
view([0 90])             %create 2D color map of temperature
xlabel('x','Fontsize',fs); ylabel('y','Fontsize',fs); zlabel('u(x,y)','Fontsize',fs);axis tight
colorbar
set(gca,'FontSize',[fs]);

print -depsc WW6_b.eps


