
% Ploting a movie of the breather solution for the modifed Kdv (mKdV)


%Params: n=1;
n=1;l=-2; k=(1/3)*sqrt(l^2+1/l); m =k*(k^2-3*l^2);a=-20;b=-20;
ti=1;tf=10;
xi=-14;xf=0;

%%Params: n=2;
%n=2;l=-2; k=(1/3)*sqrt(l^2+1/l); m =k*(k^2-3*l^2);a=-20;b=-20;
%ti=1;tf=6;
%xi=-14;xf=0;

ve=-n/l
x=linspace(xi,xf,200);
tspan=linspace(ti,tf,50);

xs=linspace(xi,xf,500);
ts=linspace(ti,tf,500);
[X,T]=meshgrid(xs,ts);
U = -2.*(l.*cos(k.*X+m.*T+a)./cosh(l.*X+n.*T+b)- ...
     l.^2./k.*sin(k.*X+m.*T+a)./cosh(l.*X+n.*T+b).^2.*sinh(l.*X+n.*T+b))./ ...
     (1+l.^2./k.^2.*sin(k.*X+m.*T+a).^2./cosh(l.*X+n.*T+b).^2);

mu=min(min(U));
Mu=max(max(U));
M=max(-mu,Mu);
pmin = -M -0.01*(M+M);
pmax = M +0.01*(M+M);


figure(1)
clf

t=ti;
u0 = -2.*(l.*cos(k.*x+m.*t+a)./cosh(l.*x+n.*t+b)- ...
      l.^2./k.*sin(k.*x+m.*t+a)./cosh(l.*x+n.*t+b).^2.*sinh(l.*x+n.*t+b))./ ...
      (1+l.^2./k.^2.*sin(k.*x+m.*t+a).^2./cosh(l.*x+n.*t+b).^2);

plot(x,u0,'LineWidth',2)
axis([xi xf pmin pmax]);
N=2;
tit=['Breather solution for the mKdV: u_t + ',num2str((N+1)*(N+2)),'u^{',num2str(N),'}u_x + u_{xxx} = 0, v_e = ',num2str(ve)];
title(tit);
xlabel('x');
ylabel('u(x,t)');

fprintf('Press any key to continue...')
pause

for t=tspan
 u = -2.*(l.*cos(k.*x+m.*t+a)./cosh(l.*x+n.*t+b)- ...
      l.^2./k.*sin(k.*x+m.*t+a)./cosh(l.*x+n.*t+b).^2.*sinh(l.*x+n.*t+b))./ ...
      (1+l.^2./k.^2.*sin(k.*x+m.*t+a).^2./cosh(l.*x+n.*t+b).^2);
 plot(x,u,'LineWidth',2)
 axis([xi xf pmin pmax]);
 title(tit);
 xlabel('x');
 ylabel('u(x,t)');
 pause(0.1);
end

fprintf('\nPress any key to continue...\n')
pause

set(gca,'FontSize',[16]);
figure(2)
clf

surfl(X,T,U);
shading interp
colormap(gray)
ylabel('t')
xlabel('x')
zlabel('u(x,t)')
title(tit);
view([15 52])

