function [u,U] = solver(T,N,V,U0,tau,split)
% ===================================================================
% Semi-discretization method for Schrödinger equation with splittings
% ===================================================================
% input parameters:
% N            defines number of line (=2*N)
% T            final Time
% V            potential (2pi-periodic)
% u0           vector with initial values
% tau          stepsize of splitting method
% spilt        splitting method  
%              split = 1: Sequential splitting
%              split = 2: Marchuk-Strang splitting
% output parameters:
% U            approximations in the grid points (ODE)
% u            approximations in the grid points (PDE)
% ====================================================================
% arrange grid
% ------------
l = -N : N-1;
x = l*pi/N;
% arrange initial value vector
% ----------------------------
U      = zeros(2*N,T);
U(:,1) = U0;
% choose splitting method and compute solution for ODE
% ----------------------------------------------------
if split == 1
   for k = 1 : T 
       U(:,k+1) = expm(i*tau*diag((i*l).^2))*fft(eye(2*N))*diag(exp(-i/2*tau*V))*ifft(eye(2*N))*U(:,k);
   end
end
if split == 2
   for k = 1 : T 
       U(:,k+1) = fft(eye(2*N))*diag(exp(-i/2*tau*V))*ifft(eye(2*N))*expm(i*tau*diag((i*l).^2))*fft(eye(2*N))*diag(exp(-i/2*tau*V))*ifft(eye(2*N))* U(:,k);
   end
end

% compute solution for PDE 
% ------------------------
u = zeros(2*N,T);
for l = 1 : T 
    for k = 1 : 2*N
        u(:,l) = u(:,l) + (exp(i*k*x)*U(k,l))';
    end
end
end
   




    
    






















    
    
    