% % code7a.m -- spectral wave w/ advective nonlinearity % % u + c u u = d u OR d u % t x xx xxx % % spectral, integrating-factor formulation: U = F[u]; r=2,3 % % (U exp(-d (ik)^r t)) = exp(-d (ik)^r t) (-0.5*c) (F[u^2]) % t x % %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - global ik choice = 5; switch choice case {1} c = 1.0; d = 0.01; r = 3; par = [c,d,r]; L = 2*pi; N = 128; dt = 0.01; Nsteps = 35; Ncycle = 4; blurb = '\bf KdV - forward dispersive regularization'; case {2,5} c = 1.0; d = -0.01; r = 3; par = [c,d,r]; L = 2*pi; N = 128; dt = 0.01; Nsteps = 30*4; Ncycle = 4*2; blurb = '\bf KdV - backward dispersive regularization'; case {3} c = 1.0; d = 0.04; r = 2; par = [c,d,r]; L = 2*pi; N = 128; dt = 0.01; Nsteps = 50; Ncycle = 8; blurb = '\bf Burgers - diffusive regularization'; case {4} c = 1.0; d = -0.002; r = 4; par = [c,d,r]; L = 2*pi; N = 128; dt = 0.01; Nsteps = 50; Ncycle = 8; blurb = '\bf 4^{th}-order hyper-diffusive regularization'; end % set grids: wavenumbers & coefficients ik = i*(2*pi/L)*(-N/2:N/2-1)'; fact = exp(-d*dt*(ik.^r)); dx = L/N; xg = (0:dx:L-dx)'; x = [xg ; L]; % IV initialization & FFT switch choice case {5} IVs = exp(-2*(xg-pi).^2); pmin = -0.1; pmax = 1.6; case {1} IVs = sin(xg); pmin = -2.5; pmax = 1.1; case {2} IVs = sin(xg); pmin = -1.1; pmax = 2.5; case {3} IVs = sin(xg); pmin = -1.1; pmax = 1.1; case {4} IVs = sin(xg); pmin = -1.5; pmax = 1.5; end t = 0; ug = IVs; u = [ug ; ug(1)]; clf; hold on; axis([0 L pmin pmax]); plot(x,u,'r'); plot(x,u,'k.','markersize',7); vg = fftshift(fft(ug))/N; % timestep loop for k = 1:Ncycle for j = 1:Nsteps [vg,tj] = code7a_rk(vg,0,dt,par); vg = vg./fact; t = t + dt; end ug = real(ifft(fftshift(vg))*N); plot(x,[ug ; ug(1)],'b'); pause(0.1) end plot(x,[ug ; ug(1)],'r'); plot(x,[ug ; ug(1)],'k.','markersize',7); title(blurb); xlabel('\bf x-axis'); ylabel('\bf u-axis')