% Domain Definition
N = 128;
PhysicalDomain = [0, 2*pi];                     % Physical Domain scaled to a 2*pi interval
h = (PhysicalDomain(2) - PhysicalDomain(1))/N;

x = linspace(h,2*pi,N);
%k = -N/2 + 1 : N/2;
k = [0:N/2-1 0 -N/2+1:-1];

dt = 0.01;
tf = 5;
t = 0:dt:tf;

% System Definition
% int the form u_t = G(u)
nu = 0.01;
uinicial = exp(-100*(x-pi).^2); 
u0 = uinicial;

G = @(u) ifft(-nu.*(k.^2).*fft(u) - 0.5i.*k.*fft(u.^2));

figure; plot(x,u0);
title(sprintf('t = %f',t(1)))

CounterPlot = 2;
j = 0;

for i = 2:length(t);
    u = u0 + dt.*G(u0);
    u0 = u;
    
    j = j + 1;
    if j == CounterPlot
        j = 0;
        plot(x,u0)
        ylim([-0.01 0.8])
        title(sprintf('t = %f',t(i)))
        pause(0.2)
    end
end