function [ u] = Method(M,C,K,dt,method,sigma,f1,X,velo,nStep,u0)


[ADir1,bDir1,nDir1] = BoundaryConditions(X,velo);

u=zeros(size(X,1),nStep+1);
u(:,1) = u0;
switch method
    case 1 % Crank-Nicolson + Galerkin
        
        A = M/dt + 0.5*(C+K+sigma*M);
        b = -(C+K+sigma*M);
        

        Ktot = [A ADir1';ADir1 zeros(nDir1,nDir1)];
      
          [L,U] = lu(Ktot);
          L=sparse(L);
          U=sparse(U);
        for n = 1:nStep
            
            ftot=[(b*u(:,n) + f1);bDir1];
            sol = U\(L\ftot);
            Du = sol(1:length(f1));
            u(:,n+1) = u(:,n) + Du;
            
        end
        
    case 2  % R22+Galerkin
        
        W=(1./24.)*[7 -1;13 5];
        w=0.5*[1;1];
        Id=[1,0;0,1];
        n=size(W,1);
        npt=size(K,1);
        A=zeros(n*npt);
        b=zeros(n*npt);
        f=zeros(n*npt,1);
        
        ADir=zeros(n*nDir1,n*npt);
        bDir=zeros(n*nDir1,1);
        
        for i=1:n
            for j=1:n
                A((i-1)*npt+1:i*npt,(j-1)*npt+1:j*npt) = Id(i,j)*M/dt + W(i,j)*(C+K+sigma*M);
                b((i-1)*npt+1:i*npt,(j-1)*npt+1:j*npt) = -w(i)*(C+K+sigma*M);
                ADir((i-1)*nDir1+1:i*nDir1,(j-1)*npt+1:j*npt)=Id(i,j)*ADir1;
                
                
            end
                f((i-1)*npt+1:i*npt)=w(i)*f1;
                bDir((i-1)*nDir1+1:i*nDir1)=bDir1;
        end
          Ktot = [A ADir';ADir zeros(n*nDir1,n*nDir1)];
        
          f=sparse(f);
          [L,U] = lu(Ktot);
          L=sparse(L);
          U=sparse(U);
          
          for n = 1:nStep

            temp=[b(1:npt,1:npt)*u(:,n);b(npt+1:2*npt,npt+1:2*npt)*u(:,n)] + f;
            
            ftot=[temp;bDir];
            sol =U\(L\ftot);
            Du = sol(1:length(f));
            Du=reshape(Du,npt,2);
            u(:,n+1) = u(:,n) + sum(Du,2);
            
         end
          
          
        
end


end

