% Solutions to heat problems

% number of terms in the fourier series.
N = 100;

% time 

flag_case = 3;


if flag_case ==1 
    % problem 2 from worksheet 25
  t =[0:0.01:0.5];
    x = [0:0.01:1];
    T = t'*ones(1,length(x));
    X = ones(length(t),1)*x;
    u = exp(-4*pi^2*100*T).*sin(2*pi*X)-exp(-25*pi^2*100*T).*sin(5*pi*X);
elseif flag_case ==2
%     from the homework Section 10.6 #9
  t =[0:0.5:20];
    x = [0:0.25:20];
    T = t'*ones(1,length(x));
    X = ones(length(t),1)*x;
    u = 3*X;
    
    for n = 1:N
    u = u + (70*cos(n*pi)+50)/(n*pi)*exp(-0.86*n^2*pi^2*T/400).*sin(n*pi*X/20);
    end
    
else
%     From worksheet 27
%     This is a wave problem
    c = 2;
  t =[0:0.5:6];
    x = [0:0.01:1];
    T = t'*ones(1,length(x));
    X = ones(length(t),1)*x;
    u  = sin(5*pi*X).*cos(5*pi*c*T)+2*sin(7*pi*X).*cos(7*pi*c*T);
end


for i = 1:length(t)
    
plot(x,u(i,:))
title(['t =  ',num2str(t(i))])
pause
end