%HW1, problem 2, MAE200B, winter 2006, Nasser Abbasi
%Print full solution U(x,t) using the selected n (number
%of fourier terms) found earlier.

close all; clear all;
L=2;
x=linspace(0,L,1000);
maxN=1000;


for t=0:0.2:5
   i=i+1;
   y=zeros(length(x),1)';
   for n=1:2:maxN
       y=y+(4000/pi)*(1/n)*sin(n*pi/4)*cos(n*x*pi/4)*exp(- (n*pi/4)^2*t);
   end
   y=1000-y;
   plot(x,y)
   hold on;
end

y(1:length(x)/2)=0;
y(length(x)/2:end)=1000;
hold on;
plot(x,y,'r');
title(sprintf('U(x,t) shown for different t, max t=%3.1f sec',t));
xlabel('x');
ylabel('U(x,t) solution');