% easy finite difference

Delta_x = 0.1;
Delta_t = 0.1;

x_vec = -1:Delta_x:1;
t_vec = 0:Delta_t:1;

n_t = length(t_vec);
n_x = length(x_vec);

u_num = zeros(n_t,n_x);

sup1 = 0;
sup2 = 0;

for k = 1:n_t-1
    
    
    for i = 2:n_x -1
    
        u_num(k+1,1) = (-( u_num(k,2)-u_num(k,1) )/Delta_x -1)* Delta_x + u_num(k,1);
    
        
    sup1 = ( u_num(k,i)-u_num(k,i-1) )/Delta_x -1;
    sup2 = -( u_num(k,i+1)-u_num(k,i) )/Delta_x -1;
    
    if sup1 > sup2
        
        u_num(k+1,i) = sup1* Delta_x + u_num(k,i);
        
    else
        
        u_num(k+1,i) = sup2* Delta_x + u_num(k,i);
        
    end
    
    end
    
    u_num(k+1,n_x) = (( u_num(k,n_x)-u_num(k,n_x-1) )/Delta_x -1)* Delta_x + u_num(k,n_x);
    
end

u_num = -u_num;

surf(t_vec, x_vec , u_num');