Solve using MatLab For the rigid frames shown in Figure dete
Solve using MatLab
For the rigid frames shown in Figure, determine the displacements and rotations of the nodes, the element forces, and the reactions. The values of E;A, and I to be used are listed next to each figure.Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%% Finite element program for truss analysis %%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 clear all;
 clc;
%%%%%%%%%%%%% Edit the following data %%%%%%%%%%%%%%
 numnode = 3; %number of nodes
 numelem = 2; %number of elements
 Nodes = [0 0; 7.071 7.071; 22.071 7.071]; %x, y coordinates
 Elements = [1 2 30e6 5;2 3 30e6 5]; % first node, second node, E, A
% Boundary conditions
 act = 1:2*numnode; % Total DOF
 act([1 2 5 6]) = []; %Boundary conditions: here u1x, u1y, u3x, u3y are zero
% Load: Load needs to be defined for the DOF\'s where no BC is defined
 F = zeros(2*numnode, 1); % Load vector
 F(3) = 0;
 F(4) = -15000; %Total pressure load of 30000 lb is divided into node 2 and 3
 %%%%%%%%%%%%%%%%%%% Inputs completed %%%%%%%%%%%%%%%%
KG = zeros(2*numnode,2*numnode); % Global stiffness matrix
 U = zeros(2*numnode, 1); % displacement vector
 strain = zeros(numelem,1); % strain in members
 stress= zeros(numelem,1); % stress in members
 axialforce =zeros(numelem,1); % axial force in members
 ElemStiff = zeros(numelem,1); %Basic element stiffness
%%%%%%%%%%%%%%%%%%% Stiffness Matrix Calculation %%%%%%%%%%%%%%%%%%%%
 for i = 1:numelem
   
 DOFs = [2*Elements(i, 1)-1, 2*Elements(i, 1), 2*Elements(i, 2)-1, 2*Elements(i, 2)]; %Holds element’s DOFs
 X1 = Nodes(Elements(i,1), 1);
 Y1 = Nodes(Elements(i,1), 2);
 X2 = Nodes(Elements(i,2), 1);
 Y2 = Nodes(Elements(i,2), 2);
 L = sqrt((X2-X1)^2+(Y2-Y1)^2); %Length of each element
 s = (Y2-Y1)/L;
 c=(X2-X1)/L;
 ms = (Y2-Y1)/L;
E = Elements(i,3); %Modulus of elasticiy of element
 A = Elements(i,4); %Cross sectional area of element
 ElemStiff(i) = A*E/L; % Basic element stiffness for each element
 Trans1 = [c 0;s 0;0 c;0 s]; % Transformation matrix
 Trans2 = (Trans1)\';
 Kelem = Trans1*[ElemStiff(i) -ElemStiff(i);-ElemStiff(i) ElemStiff(i)]*Trans2;% Element stiffness matrix
 KG(DOFs,DOFs) = KG(DOFs,DOFs) + Kelem; % Global stiffness matrix
 end
 %%%%%%%%%%%%%%%%%%%% End of Stiffness Matrix Calculation %%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%% Unknown displacement calculations %%%%%%%%%%%%%%%%%
 disp(\'============= 2D-Truss analysis Outputs ============\');
 disp(\'================ Nodal Displacements ===============\');
 U(act) = KG(act,act)\\F(act)
%%%%%%%%%%%%%%%%% Elemental force calculation %%%%%%%%%%%%%%%%%%%%%
 for i = 1:numelem
 DOFs = [2*Elements(i, 1)-1, 2*Elements(i, 1), 2*Elements(i, 2)-1, 2*Elements(i, 2)]; %Holds element’s DOFs
 X1 = Nodes(Elements(i,1), 1);
 Y1 = Nodes(Elements(i,1), 2);
 X2 = Nodes(Elements(i,2), 1);
 Y2 = Nodes(Elements(i,2), 2);
 L = sqrt((X2-X1)^2+(Y2-Y1)^2); %Holds length of element
 s = (Y2-Y1)/L;
 c=(X2-X1)/L;
 d = [c s 0 0; 0 0 c s]*U(DOFs);
 strain(i) = (d(2) - d(1))/L;
 stress(i)= Elements(i, 3)*strain(i);
 axialforce(i) = stress(i)*Elements(i,4);
 end
%%%%%%%%%%%%%%% New position of nodes %%%%%%%%%%%%
 X1 = Nodes (1,1) + U(1);
 X2 = Nodes (2,1) + U(3);
 X3 = Nodes (3,1) + U(5);
 Y1 = Nodes (1,2) + U(2);
 Y2 = Nodes (2,2) + U(4);
 Y3 = Nodes (3,2) + U(6);
% Rotation of elements in degree
 % As there is no nodal rotation DOF, so nodal rotation is not defined
 disp(\'=========== Elemental Rotations in degree =========\');
 theta1 = 45-(180/pi)*atan((Y2-Y1)/(X2-X1))
 theta2 = (180/pi)*atan((Y3-Y2)/(X3-X2))
 disp(\'============== Elemental Forces ====================\');
 axialforce
Reaction = KG*U;
 Reaction(3) = 0;
 Reaction(4) = 0;
 Reaction(6) = Reaction(6)+15000;
 disp(\'========== Reaction at the supports =================\');
 Reaction
Results/Outputs:
============= 2D-Truss analysis Outputs ============
 ================ Nodal Displacements ===============
U =
0
 0
 0.0015
 -0.0035
 0
 0
=========== Elemental Rotations in degree =========
theta1 =
0.0203
 theta2 =
0.0134
============== Elemental Forces ====================
axialforce =
1.0e+04 *
-2.1213
 -1.5000
========== Reaction at the supports =================
Reaction =
1.0e+04 *
1.5000
 1.5000
 0
 0
 -1.5000
 1.5000



