function [K m]= truss2d(p,E,A,rho ) % K = TRUSS (p1,p2,E,A) % Returns a 2-D truss element stiffness matrix in global coordinates % % p1 are the coordiniates of joint 1 of the truss element % p2 are the coordiniates of joint 2 of the truss element % E is the elastic modulus % A is the cross sectional area % m is the mass of the truss element v1=p(1,3:4)-p(1,1:2); tc=E*A/norm(v1); a=v1(1)/norm(v1); b=v1(2)/norm(v1); k1=[a^2,a*b;a*b,b^2]; K=tc*[k1,-k1;-k1,k1]; m=A*norm(v1)*rho; % --------------------------------------------------------- TRUSS