function A = formA(jmax,dx,a,isw)

  A = zeros(jmax,jmax);
  dia = 0.5*ones(jmax,1)/dx;
  if isw == 0 | isw == 3 | isw == 6 | isw == 7				% central periodic
    A = a*(-diag(dia(2:jmax),-1) + diag(dia(1:jmax-1),1));
    if isw == 0
      A(1,jmax)   = -0.5*a/dx;
      A(jmax,1)   = 0.5*a/dx;
    elseif isw == 6
      A(jmax,jmax) = a/dx;
      A(jmax,jmax-1) = -a/dx;
    elseif isw == 7
      A(jmax,jmax) = 1.5*a/dx;
      A(jmax,jmax-1) = -2.*a/dx;
      A(jmax,jmax-2) = 0.5*a/dx;
    else
    end
  elseif isw == 1 | isw == 4			% 1st order backward periodic
% $$$     A = a*(-diag(2.0*dia(2:jmax),-1) + diag(2.0*dia(1:jmax),0));
    A = a*(-diag(dia(2:jmax),-1) + diag(dia(1:jmax),0));
    if isw == 1
      A(1,jmax)   = -a/dx;
    end
  elseif isw == 2 | isw == 5			% 2nd order backward periodic
    A = a*(diag(dia(3:jmax),-2) -4*diag(dia(2:jmax),-1) + 3*diag(dia(1:jmax),0));
    if isw == 2
      A(1,jmax)   = -4*a/dx;
      A(1,jmax-1) = a/dx;
      A(2,jmax)   = a/dx;
    end
  end