function solInt(choice) %choice = 0 or 1. %0 for far off solitons moving towards each other. %1 for stationary, but overlapping solitons. %plots solitons in time, with x-t plot, and image plot. % variable parameters......... if choice == 0 x0 = 3; %soliton displacement T = .3; %time duration dt = .00003; %time step k = 10; %wave number else x0 = 1; T = 1.3; dt = .0001; k = 0; end %............................ % set parameters .......... xmin = -10; xmax = 10; n = 150; %lattice points c = 2; %width and height of soliton. note: must match non-linearity strength, B. B = -2; %non-linear strength. % ................. dx = (xmax-xmin)/n; %spatial step x = xmin + (1:n)'*dx; %x is col vec a = -1/(dx)^2; b = 1/(2*dx^2); % creation of K the sparse matrix D = sparse(1:n,1:n,a,n,n); E = sparse(2:n,1:n-1,b*ones(1,n-1),n,n); K = E+D+E'; U = c*sech(c*(x-x0)).*exp(-1i*k*x) + c*sech(-c*(x+x0)).*exp(1i*k*x); I = speye(n,n); % keeps everything sparse t = 0; %using CN scheme in paper... Uold = U; Unew = zeros(n,1); modT = 100; xtU = zeros(n,(T + modT*dt)/(modT*dt)); %records U as time goes on while t < T if (mod(floor(t/dt),modT)==0) xtU(:,floor(t/(modT*dt) + 1)) = U.*conj(U); plot(x, [U.*conj(U) real(U) imag(U)]); axis([xmin xmax -1 15]); text(1,1, sprintf('t=%g, prob=%g', t, dx*dot(U,U))); drawnow; end Unew = (I - 1i*dt*K)\((I + 1i*dt*K)*U - B*1i*dt*(3/2*conj(U).*U.*U - 1/2*conj(Uold).*Uold.*Uold)); Uold = U; U = Unew; t = t + dt; end figure; surf(xtU); colorbar; if choice == 0 text(50,100,25,'seperated soliton collision'); else text(75,100,25,'overlapping solitons'); end figure; imagesc(xtU'); set(gca,'ydir','normal'); colorbar;