% 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 = [0:N/2-1 0 -N/2+1:-1];

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

% System Definition
% int the form u_t = G(u)
nu = 0.01; 
u = zeros(length(t),length(x));
u(1,:) = exp(-50*(x-pi).^2);

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

for i = 1:length(t)-1;
    k1 = G(u(i,:));
    k2 = G(u(i,:) + 0.5.*dt.*k1);
    k3 = G(u(i,:) + 0.5.*dt.*k2);
    k4 = G(u(i,:) + dt.*k3);

    u(i+1,:) = u(i,:) + (dt/6).*(k1 + 2.*k2 + 2.*k3 + k4);

end

waterfall(x,t,real(u))
xlabel('x')
ylabel('t')
zlabel('u')