I'm trying to solve the following equation$$u_t = u_{xx} + u(1-u^2), u_x(\pm 1) = 0,$$using the Fourier cosine transform. The nonlinear term gives a convolution which I would rather avoid, which is why I wanted to try a pseudo-spectral method.In MATLAB I have the following script (simplified as much as possible)function TestCosineSeries()Nx = 32;x = linspace(-1,1,Nx)';f = tanh(1000*x);dt = 1e-3;Nt = 100;for k = 1 : Nt    t = k*dt    [t,y] = ode45(@(t,y)RHS(t,y,L),[0 dt],f);    f = y(end,:);endendfunction duout = RHS(t,u,L)N = length(u);uhat = fft(u);kappa = fftshift((-N/2:N/2-1)');DDuhat = -pi^2*kappa.^2.*uhat;DDu = ifft(DDuhat);duout = DDu + (1-u.^2).*u;endI imagine I'm doing something wrong in using the cosine series (maybe I can't use FFT). Any help would be appreciated!
Pseudo-Spectral cosine transform
matlab;spectral method