function ppde1
% ppde1.m MCS571 Simple Test  for u_t= A*u_{xx}, 
% BC: u(0,t)=0=u(2,t); IC u(x,0)=100*(1-|x-1|)
% 
clc % clear variables, but must come before globals, 
    %    else clears globals too.
clf % clear figures
%
m = 4; n = 6; A = 1/2; % Input: x-divisions, t-divisions, Diffusion Coeff.;
h = (2-0)/m;  % x-step
f=0; % figure counter
fprintf('\n m=%i; n=%i; h=%f; A=%f;',m,n,h,A);
Ar=[0.5,0.25,1.0]; % Marginally Stable, Stable,  Unstable Cases;
stitle = {'PPDE EEM: u_t=0.5*u_{xx}, Marginally Stable' ...
        ,'PPDE EEM: u_t=0.25*u_{xx}, Stable' ...
        ,'PPDE EEM: u_t=1.0*u_{xx}, Unstable'};
for ir = 1:3
    r=Ar(ir)/A;  k=r*h^2;
    f=f+1;
    fprintf('\nFig-%i: %s; r=%f; k =%f; Ar=%f' ...
        ,f,'PPDE EEM: u_t=A*u_{xx}',r,k,Ar(ir)); 
    X=(0:m)'*h; % Need convert row to column vector & Scale by h;
    U=zeros(m+1,n+1);
    U(:,1) = u0(X);
    for j=2:n+1
        for i = 2:m
            U(i,j) = Ar(ir)*(U(i+1,j-1)+U(i-1,j-1))+(1-2*Ar(ir))*U(i,j-1);
        end
    end
    figure(f);
    hold off;
    for j = 1:n+1
        plot(X,U(:,j),'b-','LineWidth',3);
        hold on;
    end
    htitle=title(stitle(ir));
    hxlabel=xlabel('x');
    hylabel=ylabel('U(x_i,t_j), j=0:n');
    haxis = gca;
    set(haxis,'Fontsize',20,'FontName','Helvetica','FontWeight','Bold' ...
        ,'linewidth',2);
    set(htitle,'Fontsize',24,'FontName','Helvetica','FontWeight','Bold');
    set(hylabel,'Fontsize',24,'FontName','Helvetica','FontWeight','Bold')
    set(hxlabel,'Fontsize',24,'FontName','Helvetica','FontWeight','Bold');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function u0v = u0(x) % Sample Initial Condition: Triangular Distribution
u0v = 100*(1-abs(x-1));
% END u0