function upwind()
  // constructing signal as follows:
  // sig   00000 11111 11111 00000 00000 ...
  // idx  -4   0 1     6     11    16    ...
  signal = zeros(50,1);
  signal(5:15,1) = 1;
  
  s  = 20;      // steps
  a  = 2.0;     // parameter a
  dx = 0.1;     // delta x
  dt = 0.025;   // delta t
  
  // plot original signal
  plot2d(1:50,signal,style=1)
  
  for i=1:s
    // build boundary-zero-ed signal and shift one to left
    n = size(signal,1)
    tmp = zeros(n+2,1)
    tmp(2:n+1,1) = signal(1:n,1);

    for j=1:n
     signal(j,1) = dt * a / dx * (tmp(j,1) - tmp(j+1,1)) + tmp(j+1,1)
    end
    steps=5
    if modulo(i,steps) == 0
      plot2d(1:50,signal,style=i/steps)
    end
  end
endfunction


function upwindWithBoundary()
  // constructing signal as follows:
  // sig   00000 11111 11111 00000 00000 ...
  // idx  -4   0 1     6     11    16    ...
  signal = zeros(50,1);
  signal(5:15,1) = 1;
  
  s  = 20;      // steps
  a  = 2.0;     // parameter a
  dx = 0.1;     // delta x
  dt = 0.025;   // delta t
  
  // plot original signal
  plot2d(1:50,signal,style=1)
  
  for i=1:s
    // build boundary-zero-ed signal and shift one to left
    n = size(signal,1)
    tmp = zeros(n+2,1)
    tmp(2:n+1,1) = signal(1:n,1);
    tmp(n+2,1) = tmp(n+1,1);
    //bla = tmp(n-4:n+2,1);
    //disp(bla')

    for j=1:n
     signal(j,1) = dt * a / dx * (tmp(j,1) - tmp(j+1,1)) + tmp(j+1,1)
     if j == n
      signal(n,1) = tmp(j,1) + tmp(j+1,1)
      end
    end
    steps=5
    if modulo(i,steps) == 0
      plot2d(1:50,signal,style=i/steps)
    end
  end
endfunction
