function [cmm]=Q8_3Dcmm(X, Y, Z, rho)

%X=[5 12 13 7 5 12 13 7];
%Y=[6 8 11 12 6 8 11 12];
%Z=[-10 -10 -10 -10 10 10 10 10];
%E=2e11;
%Nu=0.25;
%Q8_3Dk(X,Y,Z,E,Nu)
%




syms Xi Eta Zeta real;



XiC=[-1 1 1 -1 -1 1 1 -1];
EtaC=[-1 -1 1 1 -1 -1 1 1];
ZetaC=[-1 -1 -1 -1 1 1 1 1];

Ni=[ ( (XiC(2)-Xi)*(EtaC(4)-Eta)*(ZetaC(5)-Zeta ) )/( (XiC(2)-XiC(1))*(EtaC(4)-EtaC(1))*(ZetaC(5)-ZetaC(1))), ...
        ( (XiC(1)-Xi)*(EtaC(3)-Eta)*(ZetaC(6)-Zeta ) )/( (XiC(1)-XiC(2))*(EtaC(3)-EtaC(2))*(ZetaC(6)-ZetaC(2))), ...
        ( (XiC(4)-Xi)*(EtaC(2)-Eta)*(ZetaC(7)-Zeta ) )/( (XiC(4)-XiC(3))*(EtaC(2)-EtaC(3))*(ZetaC(7)-ZetaC(3))), ...
        ( (XiC(3)-Xi)*(EtaC(1)-Eta)*(ZetaC(8)-Zeta ) )/( (XiC(3)-XiC(4))*(EtaC(1)-EtaC(4))*(ZetaC(8)-ZetaC(4))), ...
        ( (XiC(6)-Xi)*(EtaC(8)-Eta)*(ZetaC(1)-Zeta ) )/( (XiC(6)-XiC(5))*(EtaC(8)-EtaC(5))*(ZetaC(1)-ZetaC(5))), ...
        ( (XiC(5)-Xi)*(EtaC(7)-Eta)*(ZetaC(2)-Zeta ) )/( (XiC(5)-XiC(6))*(EtaC(7)-EtaC(6))*(ZetaC(2)-ZetaC(6))), ...
        ( (XiC(8)-Xi)*(EtaC(6)-Eta)*(ZetaC(3)-Zeta ) )/( (XiC(8)-XiC(7))*(EtaC(6)-EtaC(7))*(ZetaC(3)-ZetaC(7))), ...
        ( (XiC(7)-Xi)*(EtaC(5)-Eta)*(ZetaC(4)-Zeta ) )/( (XiC(7)-XiC(8))*(EtaC(5)-EtaC(8))*(ZetaC(4)-ZetaC(8)))];
    
x=Ni*X';
y=Ni*Y';
z=Ni*Z';

J=[ diff(x,Xi), diff(y,Xi), diff(z,Xi) ; diff(x,Eta), diff(y,Eta), diff(z,Eta); diff(x,Zeta), diff(y,Zeta), diff(z,Zeta)];


NTNJ1=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{ -1/sqrt(3), -1/sqrt(3), -1/sqrt(3)});
NTNJ2=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{  1/sqrt(3), -1/sqrt(3), -1/sqrt(3)});
NTNJ3=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{  1/sqrt(3),  1/sqrt(3), -1/sqrt(3)});
NTNJ4=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{ -1/sqrt(3),  1/sqrt(3), -1/sqrt(3)});

NTNJ5=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{ -1/sqrt(3), -1/sqrt(3), 1/sqrt(3)});
NTNJ6=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{  1/sqrt(3), -1/sqrt(3), 1/sqrt(3)});
NTNJ7=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{  1/sqrt(3),  1/sqrt(3), 1/sqrt(3)});
NTNJ8=subs(Ni'*Ni*det(J)*rho,{Xi, Eta, Zeta},{ -1/sqrt(3),  1/sqrt(3), 1/sqrt(3)});



cmm=NTNJ1+NTNJ2+NTNJ3+NTNJ4+NTNJ5+NTNJ6+NTNJ7+NTNJ8






   