In: Mechanical Engineering
ndof = 8 ;
ne = 3 Kg = zeros(ndof) ;
for n = 1: ne %
Form the upper triangular portion of
Kg d1 = 2*n-1; d2 = 2*n; d3 = 2*n+1;
d4 = 2*n+2; Kg(d1,d1) = Kg(d1,d1) +k1;
Kg(d1,d2) = Kg(d1,d2) +k2 ;
Kg(d1,d3) = Kg(d1,d3) - k1;
Kg(d1,d4) = Kg(d1,d2) +k2 ;
Kg(d2,d2) = Kg(d2,d2) +k3;
Kg(d2,d3) = Kg(d2,d3) -k2 ;
2 Kg(d2,d4) = Kg(d2,d4) +k4;
Kg(d3,d3) = Kg(d3,d3) +k1;
Kg(d3,d4) = Kg(d3,d4) - k2 ;
Kg(d4,d4) = Kg(d4,d4) +k3;
end
end
Complete the Kg matrix for i = 2:
ndof for j = i+1 to ndof Kg(j,i) = Kg (i, j) ;