%% exercise number 2
%problem characteristics
U=0.7;%convection velocity
delta_x=0.01; %space discretization 
L=1; %max length of our domain
T=1; %max time considered

N=L/delta_x; %number of intervals in space
K=100; %number of intervals in time

%two initial conditions
square_pulse=@(x) heaviside(x-0.1) - heaviside(x- 0.3); 
gauss_signal=@(x) exp(-10*(4*x - 1).^2);

[x,t,c] = UW_scheme(L,N,T,K,U,square_pulse);
ex_sol=@(x,t) square_pulse(x-U*t);
f1=figure(1);
set(f1, 'Position', [10 10  height]);
for ii=1:K+1
    clf(f1)
    hold on 
    plot(x,c(:,ii)','-bo');
    plot(x,ex_sol(x,t(ii)));
    hold off
    legend("aproximated solution","exact solution")
    xlim([0 L])
    ylim([0 1.1])  
    pause(0.02);
end

[x,t,c] = UW_scheme(L,N,T,K,U,gauss_signal);
ex_sol=@(x,t) gauss_signal(x-U*t);
f2=figure(2);
for ii=1:K+1
    clf(f2)
    hold on 
    plot(x,c(:,ii)','-bo');
    plot(x,ex_sol(x,t(ii)));
    legend("aproximated solution","exact solution")
    xlim([0 L])
    ylim([0 1.1])  
    pause(0.02);
end

