% Set up grid and initial data:
 eps = 0.2;
 L = 20; N = 256; dt = 8/N^2; x = (L/N)*(-N/2:N/2-1)';
 clf, drawnow, set(gcf,'renderer','zbuffer')
 u = exp(-0.5*x.^2);
 v = fft(u); k = [0:N/2-1 0 -N/2+1:-1]';
% Solve PDE and plot results:
 tmax = 5; nplt = floor((tmax/25)/dt); nmax = round(tmax/dt);
 udata = u; tdata = 0; h = waitbar(0,'please wait...');
 g = -1i*dt*pi/L*k;
 ik3 = eps*(2*pi/L)^2*k.^2;
 E = exp(-dt*ik3/2); E2 = E.^2;
 for n = 1:nmax
 t = n*dt;
 a = g.*fft(real( ifft( v ) ).^2);
 b = g.*fft(real( ifft(E.*(v+a/2)) ).^2); % 4th-order
 c = g.*fft(real( ifft(E.*v + b/2) ).^2); % Runge-Kutta
 d = g.*fft(real( ifft(E2.*v+E.*c) ).^2);
 v = E2.*v + (E2.*a + 2*E.*(b+c) + d)/6;
 if mod(n,nplt) == 0
 u = real(ifft(v)); waitbar(n/nmax)
 udata = [udata u]; tdata = [tdata t];
 end
 end
 waterfall(x,tdata,udata'), colormap(1e-6*[1 1 1]); view(20,25)
 xlabel x, ylabel t, axis([-L/2 L/2 0 tmax 0 max(max(udata))]), grid off
 set(gca,'ztick',[0 max(max(udata))]), close(h), pbaspect([1 1 .13])