% This routine computes the Maslov index of an exact solution
% of a fifth-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 1: Hamiltonian systems on a 4−dimensional 
% phase space, Physica D 238 p.1841-1867 (2009) 

clear
global sigma_matrix
global maslov_form
global maslov_matrix

%% User-defined input 
k=2;				
p=1;				
P = (p^2+4*p+8)/(2*(p+2));	
dx=1/1000;
x=(-40:dx:40)';
sol=((p+4)*(3*p+4)/(8*(p+2)))^(1/p)*sech((x)*p./sqrt(8*(p+2))).^(4/p);
a=1-(p+1)*sol.^p;


% Matrix A(x). The coefficients of the matrix must be separated by a comma or
% a semi-colon.
strA=sprintf('%s%1.16f%s',',,,1;,,1,',P,';-a(1),,,;,1,,');

maslov_kdv5=@(h)(maslov(a-h,1-h,dx));


%%  Exterior algebra setup. (This section should not need to be modified)

[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.

h=0
[maslov_index,evans_function]=maslov_kdv5(h)
h=-100
[maslov_index,evans_function]=maslov_kdv5(h)
h=1.1
[maslov_index,evans_function]=maslov_kdv5(h)
h=-.1
[maslov_index,evans_function]=maslov_kdv5(h)
