function  prob2()

clf

% --------------------------
% User input parameters
% --------------------------

choice = 2;

if choice == 1
    f = @(y) ones(size(y));
    P = 20;   % Number of terms in the series
elseif choice == 2
   f = @(y) sin(pi*y);
   P = 1;
end

% --------------------------
% Numerical parameters
% --------------------------

N = 500;

x = linspace(0,1,N+1);
y = x;

[xm,ym] = meshgrid(x,y);

% --------------------------
% Series solution
% --------------------------

u = zeros(size(xm)); 

for m = 1:P
    if choice == 1
        n = 2*m - 1;
        Bn = 4/(pi*n);
    elseif choice == 2
        n = m;
        if n == 1
            % An = 1/sinh(pi);
            Bn = 1;
        else
            % An = 0;
            Bn = 0;
        end
    end
    An = Bn/sinh(pi*n);
    u = u + An*sinh(n*pi*xm).*sin(n*pi*ym);  
    fprintf('%5d %12.4e\n',n,max(abs(An*sinh(n*pi*xm(:)))));
end

% --------------------------
% Plot results
% --------------------------

h = surf(xm,ym,u);
hold on;
yf = linspace(0,1,100);
zf = f(yf);
xf = 0*zf + 1;
plot3(xf,yf,zf,'k','linewidth',3);

set(h,'edgecolor','none');

daspect([1,1,1]);

camlight
shg


end