clear clc %M= 11; %K= 1100; A=1 ; nn=10; M=zeros(nn,nn);%global mass matrix K=zeros(nn,nn); F=zeros(nn,1); Mel= [10,0;0,10];% element mass Kel= [1100,-1100;-1100,1100]; % element stiffness matrix for I=1:nn M(I,I)=10; end Kel=[1100,-1100;-1100,1100]; for i=1:nn-1 j=i+1; K=LinearBarAssemble (K,Kel,i,j); end function y=LinearBarAssemble(K,Kel,i,j) K(i,i)=K(i,i)+Kel(1,1); K(i,j)=K(i,j)+Kel(1,2); K(j,i)=K(j,i)+Kel(2,1); K(j,j)=K(j,j)+Kel(2,2); %K(1:nn-1,nn)=0 y=K;