% Function "stiff" which is called to generate the stiffness matrix for
% each element. 

% The inputs for this function are ANGLE in DEGREES (theta)with respect to
% the horizontal, the STIFFNESS CONSTANT (k=AE/L) and the 4 INDICES of the
% displacements for the truss element in the order node_1_horizontal, node
% 1_vertical, node_2_horizontal and node_3_vertical these are a,b,c and d)

% The function returns a 12x12 matrix,Kg, after placing the components of
% the element stiffness matrix at the correct place as if Kg is the global
% stiffness matrix.

function Kg = stiff(theta,k,a,b,c,d);

%   Calculation of local stiffness matrix
t=theta*pi/180;
K =k*[(cos(t))^2,sin(t)*cos(t), -(cos(t))^2, -sin(t)*cos(t)
    sin(t)*cos(t),(sin(t))^2, -sin(t)*cos(t), -(sin(t))^2
-(cos(t))^2, -(sin(t))*(cos(t)), (cos(t))^2, sin(t)*cos(t)
-sin(t)*(cos(t)), -(sin(t))^2, (sin(t))*(cos(t)), (sin(t))^2];

%   Placing the components of local stiffness matrix to the correct
%   location in a 12 x 12 matrix - as if it is global stiffness matrix

Kg=zeros(12,12);
Kg([a,b,c,d],[a,b,c,d])=K;
end
