% Number of cells and timesteps
nx = 100;
nt = 5;

% Size of total domain
width = 100;

% Size of each cell
dx = width / nx;

% Heat diffusion coefficient
kappa = 1.0;

% Initial heat distribution
u0 = rand(1, nx);
u1 = u0;

% (Center) position of each cell
x = linspace(0.5*dx, width-0.5*dx, nx);

% Maximum size of timestep (according to CFL)
cfl = 0.8;
dt = cfl*dx*dx/(2*kappa);

% Plotting help
figure('units','normalized','outerposition',[0 0 1 1])
simulated_graph = plot(x, u0, '.:');
simulated_graph.YDataSource = 'u0';
axis([0, width, min(u0), max(u0)]);
legend('Heat');
title('Heat equation in 1D');

% Loop over time for nt timesteps
for j=0:nt
    for i=2:nx-1
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % Dette er linjen du må endre på %
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        u1(i) = u0(i);
    end
    u0 = u1;
    
    % Update plot
    refreshdata;
    drawnow;
    pause(0.2);
end



