% This routine computes the Maslov index of an exact solution
% of a seventh-order Korteweg-de Vries equation. The algorithm 
% is described with details in:
% F.Chardard, F.Dias, T.J.Bridges. Computing the Maslov index 
% of solitary waves. Part 2: Phase space with dimension greater 
% than four, submitted to Physica D.
% http://www.umpa.ens-lyon.fr/~fchardar/publications/Maslov_part2_10June_update.pdf
% The exact solution was first described in:
% B. R. Duffy & E. J. Parkes, Travelling solitary wave solutions to 
% a seventh-order generalized KdV equation, Phys. Lett. A 214 (1996), 
% no. 5-6, 271–272.

clear
clear
global sigma_matrix
global maslov_form
global maslov_matrix
%% User-defined input
k=3;

sigma=2159/10000;  %Solution A                                
c=710000/(2159^2);          
a6=1039500/(2159^2);        
a4=a6;                      
kk=sqrt(25/2159);            
                            
                    
dx=.01;                  
x=(-40:dx:40)';                
phiinf=0;                   
phi=a6*sech(kk*x).^6+a4*sech(kk*x).^4;

% Matrix A(x). The coefficients of the matrix must be separated by a comma,
% a semi-colon, or a space.

strA=sprintf('%s%2.16f%s','0 1 0 0 0 0;0 0 1 0 0 0;0 0 0 0 0 ',1/sigma,...
     ';a 0 0 0 0 0;0 1 0 -1 0 0;0 0 1 0 -1 0')

maslov_kdv7=@(lambda)(maslov(-lambda+c-phi,-lambda+c-phiinf,dx));

%%  Exterior algebra setup.

[matrixA compound_matrix,sigma_matrix,maslov_form,maslov_matrix]=...
    exterior_algebra(strA,k);

fd=fopen('compound_matrix.m','w');
fprintf(fd,'%s',compound_matrix);
fclose(fd);

fd=fopen('matrixA.m','w');
fprintf(fd,'%s',matrixA);
fclose(fd);

clear matrixA compound_matrix

%%  Computation of the Maslov index of the exact solitary wave.

lambda=-1:.01:1;res=[];
for h=lambda
    [maslov_index,evans_function]=maslov_kdv7(h);
    res=[res,maslov_index]
end
plot(lambda,res)
