%This function returns the value of the strain and stress in a given
%element. The function takes the angle of the link in degrees with respect
%to the horizontal, displacement values at all nodes in sequence
%node_1_horizontal, node_1_vertical, node_2_horizontal and node_2_vertical,
%Youngs modulus (YM), and the length of the link

function [strain, stress] = StressStrain(theta,Ue,YM,length)

t=theta*pi/180;
R=[cos(t) sin(t) 0 0;0 0 cos(t) sin(t)];      %geometric relationship between the displacements written in the global and local coordinates

ue=R*Ue;   % calculation of displacement along the lnegth of the link

strain=(ue(2)-ue(1))/length; %definiton of strain
stress=strain*YM;            %Hooke's law
end

