close all
clear
N = 200;
y = zeros(1, N);
c = 2;
dt = 0.02;
L = 100;
dx = L/N;
max_t = 40;
for (t = 0:dt:max_t)
    % update
    y_new(2:N-1) = y(2:N-1) + c^2 * dt/dx^2 * (y(1:N-2) - 2* y(2:N-1) + y(3:N));
    % left boundary  
    y_new(1) = 1; % constant temp at LHS
    % right boundary
    y_new(N) = 0; % constant temp at RHS
    y = y_new;
    plot(linspace(0, L, N), y);
    ylim([-1, 1]);
    hold on;
    plot(0, y(1), '.', 'markersize', 15);
    hold off;
    xlabel('Distance');
    ylabel('Temperature');
    text(L/2, 0.8, sprintf('Time = %.2f s', t));
    pause(0.01);    
end
