function [m1,m2] = matrix_elementary(s)
% This function generates the elementary Mass matrix m1  and the elementary Rigidity matrix m2 for the P1-element method.
% s is a vector containing the (x,y)-coordinates of the three vertices of a given Triangle, meaning that s is of size 3x2.
% We remind that the area of a triangle can be computed from their coordinates (Xa,Ya),(Xb,Yb) and (Xc,Yc), the area S = 1/2*| det(Xb-Xa Xc-Xa;Yb-Ya Yc-Ya) |
  
  area_tri = 0.5*abs((s(2,1)-s(3,1))*(s(3,2)-s(1,2))-(s(2,2)-s(3,2))*(s(3,1)-s(1,1)));

%Mass Matrix

  m1 = area_tri/12*(ones(3)+eye(3));
  N = zeros(3,2);
  N(1,:) = s(3,:)-s(2,:);
  N(2,:) = s(1,:)-s(3,:);
  N(3,:) = s(2,:)-s(1,:);

%Stiffness Matrix

  m2 = N*N';
  m2 = m2/(4*area_tri);

end
