I am trying to solve the Viscous Burgers equation using the spectral method.$$u_t+uu_x = Du_{xx}$$ where $D$ is a constant (chosen to be zero) and with the initial condition$$u(x,0) = exp(-x/0.2)^2$$I use the spectral method for the spatial derivative $u_x$ and $u_{xx}$ and the leapfrog method for the time derivative $u_t$.That will give the an equation for the next time step:$$u_{j}^{k+1} = 2*\Delta t*u_{j}^{k-1} -2* \Delta t [f^{-1}(-1N^2 \pi^2 f(U_{j}^{k})) - u_{j}^{k}* f^{-1}(iN \pi f(U_{j}^{k}))]$$$u_{j}^{k-1}$ is computed by one step with Runge-Kutta and $u_{j}^{k}$ is from the initial condition.The plot I am getting right now is:Can anyone see my mistake?Code:w = 0.2;A = 1;n = 2^8;deltat = 2*A/(8*n); h = 2*A/n;   %step size for Nx = -A:h:A-h; %Discretization of Ntm = 0:deltat:2;u = @(x) exp(-(x/w).^2);N = -n/2:n/2-1;D = 0;sol = zeros(length(tm),length(x)); % rows are space / columns are time;u0 = u(x); % initial condition at t = 0sol(1,:) = u0;[t, ksol] = ode45(@f2,[0 deltat], u0);u1 = ksol(end,:);sol(2,:) = u1;for k = 3:length(tm)+1    f_hat = fft(sol(k-1,:));    % fft transform    umiddle = 2 * deltat * ( D * ifft(-1 * pi^2 * fftshift(N.^2) .* f_hat)...                             - u(x+h*(k-1)) .* ifft(1i * pi * fftshift(N) .* f_hat) );     sol(k,:) = sol(k-2,:) +  umiddle;endmesh(real(sol));Functionfunction sol = f2(~,u)D = 0;n = 2^8;N = -n/2:n/2-1;   sol = D * ifft(-1 * pi^2 * fftshift(N.^2) * fft(u,n))...               - u * ifft(1i * pi * fftshift(N) * fft(u,n));end
Numerically computing Viscous Burger
matlab;fourier analysis;spectral method;fourier transform