function [ PHISOL ] = calculgramp(NPTg,Tg,dtg,z0Mg,dz0Mg,alpha0Mg,dalpha0Mg,xeqMg,Radg,B0g,C0g,F0g,a0g,b0g)
%==================
% construction de la matrice de Gram
%==================
GRAMM=zeros(4,4);
%==================
phi0=0.*linspace(1,4,4);
deltaphi0=0.*linspace(1,4,4);
Lsec=linspace(1,2,4)*0.;
%
     P1dot=linspace(1,2,NPTg)*0.;
     P2dot=linspace(1,2,NPTg)*0.;
     Q1dot=linspace(1,2,NPTg)*0.;
     Q2dot=linspace(1,2,NPTg)*0.;
     betag=linspace(1,2,NPTg)*0.;
     %
       r=sqrt(a0g/b0g);
       cc=sinh(r*Tg);
%=================
for k1=1:4
  for i1=1:4
        if(i1 == k1)
                phi0(i1)=1;
        else
                phi0(i1)=0;
        end
  end
    [P1,P2]=soluedo(Radg,NPTg,dtg,phi0);
     P1dot(1)=phi0(2);
     P2dot(1)=phi0(4);
    
     for i=2:NPTg
         P1dot(i)=(P1(i)-P1(i-1))/dtg;
         P2dot(i)=(P2(i)-P2(i-1))/dtg;
     end
     intj=0;
     for iii=1:NPTg
         intj=intj+sinh(r*(NPTg-iii+1)*dtg)*(C0g(1)*P1dot(iii)+C0g(2)*P2dot(iii)-B0g(1)*P1(iii)-B0g(2)*P2(iii));
     end
     intj=intj*dtg;
     %
     
     for kkk=1:NPTg
         resi=0.;
         for jjkk=1:kkk
        
         resi=resi+(C0g(1)*P1dot(jjkk)+C0g(2)*P2dot(jjkk)-B0g(1)*P1(jjkk)-B0g(2)*P2(jjkk))*sinh(r*(kkk-jjkk+1)*dtg);
         end
         betag(kkk)=(1/(r*b0g))*((sinh(r*dtg*(kkk-1))/cc)*intj-resi*dtg);
     end
         betag(1)=0.;
         %betag(NPTg)=0.;
     Lsec(k1)=dz0Mg*phi0(1)+dalpha0Mg*phi0(3)-z0Mg*phi0(2)-alpha0Mg*phi0(4)+xeqMg(1)*P1dot(NPTg)+xeqMg(2)*P2dot(NPTg);
     squatro=0;
     for jkl=1:NPTg
         squatro=squatro+F0g(1)*P1(jkl)+F0g(2)*P2(jkl);
     end
     Lsec(k1)=Lsec(k1)+squatro*dtg;
  %==============
   for k2=k1:4
       for i2=1:4
          if(i2 == k2)
               deltaphi0(i2)=1;
          else
               deltaphi0(i2)=0;
          end
        end
%==================
% Remplissage des solution elementaire
%==================
    [Q1,Q2]=soluedo(Radg,NPTg,dtg,deltaphi0);
     Q1dot(1)=deltaphi0(2);
     Q2dot(1)=deltaphi0(4);
     for i=2:NPTg   
      Q1dot(i)=(Q1(i)-Q1(i-1))/dtg;
      Q2dot(i)=(Q2(i)-Q2(i-1))/dtg;
     end
%========   
% calcul des termes de GRAMM
%========
sbis=0;
        for jj=1:NPTg
        
        sbis=sbis+(C0g(1)*Q1dot(jj)+C0g(2)*Q2dot(jj)-B0g(1)*Q1(jj)-B0g(2)*Q2(jj))*betag(jj);
        
        end
        
    
    GRAMM(k1,k2)=sbis*dtg;
    GRAMM(k2,k1)=GRAMM(k1,k2);
   end
end
%======
%  calcul de PHI
%======
PHISOL=linsolve(GRAMM,Lsec');


end



