%% In Class Demnonstration
% Dirchlet Boundary Conditions

%% Parameters:

a=0; %Spatial Domain
b=pi;

n=50; %Number of spatial points
m=10000; %Number of temporal points

frame=100; %Number of frames before plotting

%% Constuction of spatial-temporal mesh

x=linspace(a,b,n);
dx=x(2)-x(1);

dt=1/2*(dx^2/gamma); %Satisfying CFL condition
t=linspace(0,(m-1)*dt,m);

%% Initial profile
u0=pi/2-abs(x-pi/2);

%% Construction of second derivative matrix

%% Dirchlet Boundary Conditions


%% Constuction of spatial-temporal mesh


%% Initial profile

%% Construction of second derivative matrix



%% Initialization of Matrix

u=zeros(n,m); %Initialization of distribution
u(:,1)=u0;

vidObj = VideoWriter('Dirichlet.avi');
open(vidObj);

% Plotting Initial Condition
figure('units', 'normalized', 'outerposition', [0,0,1,1]);
hold on;
plot(x,u0,'LineWidth',2);
ylabel('$u(x,t)$','Interpreter','latex','Fontsize',36);
xlabel('$x$','Interpreter','latex','Fontsize',36);
title(strcat('$t=$',num2str(t(1))),'Interpreter','latex','Fontsize',36);
axis([a,b,-1,1]);
ax=gca;
ax.FontSize = 36;
drawnow;

currFrame = getframe(gcf);
writeVideo(vidObj,currFrame);

% Looping through Changes in time
for i=1:m-1
    u(:,i+1)=u(:,i)+(gamma*D2*u(:,i))*dt;
    
    u(1,i+1)=0; %boundary conditions
    u(n,i+1)=0; %boundary conditions
    
    if mod(i,frame)==1, %Plot every 100th iterate
        clf;
        plot(x, u(:,i+1),'LineWidth',2);
        ylabel('$u(x,t)$','Interpreter','latex','Fontsize',36);
        xlabel('$x$','Interpreter','latex','Fontsize',36);
        title(strcat('$t=$',num2str(t(i))),'Interpreter','latex','Fontsize',36 );
        axis([a,b,-1,1]);
        ax=gca;
        ax.FontSize = 36;
        drawnow;
        
        currFrame = getframe(gcf);
        writeVideo(vidObj,currFrame);
    end
    
end

close(vidObj);

