Plane Truss Calculation Using Matrix Stiffness Method in MatLab

 PROBLEM

Consider the plane truss shown below. Given E = 210 GPa and A = 0.005 m2 , determine:

1. The golbal stiffness matrix for the structure.

2. The horizontal and vertical displacements at all nodes.

3. The horizonta and vertical reactions at nodes 1 and 8.

4. The stress in each element 


SOLUTION
- Input all the data into an excel file as below:
a. Number of Node (NN):  input the amount of all nodes (8 nodes shown in red color)
b. Number of Element (NE): input the amount of all members (13 members shown in green color)
c. Number of Support (NS): input the amount of all supports ( 2 pin support shown in green color)
d. Number of Load (NL): input the amount of point loads (Loads are applied to 3 nodes)
e. Node: input the coordinates of all nodes, the origin of the axis is node 1 (X=0, Z=0) until node 8 (X=12, Z=0)
f. Element: Input the elements detail such as Young’s Modulus (E) and Cross Sectional Area (A) and also the specify the start and end nodes. E = 210 GPa = 2.1*108 kPa
g. Support: Input the node at support with the constraint type (0 is pin support, 1 is only horizontal reaction, and others is only vertical reaction(roller support))
h. Force: Input the nodes that is applied the load on by separated as two load directions, horizontal and vertical. From figure above, there are 3 nodes are applied the load, node 4 (Fx = -5kN, Fy= -20kN), node 2 (Fy=-5kN), node 6 (Fy=-5kN)

- Write a script file in matlab to calculate as below:

» clc
» clear all
» close all
»
» format short
» % input data (input all the data into an excel file and using the xlsread
» % to call the data into matlab)
» % Node 1 location (loc) is X=0, Z=0
» NN=xlsread('Truss.xlsx','input','C1');
» loc=xlsread('Truss.xlsx','input','A8:C42');
» for j=1:NN
»     i=loc(j,1);
»     X(i)=loc(j,2);
»     Z(i)=loc(j,3);
» end
» %Elements detail with Young's Modulus, Area and Direction
» NE=xlsread('Truss.xlsx','input','C2');
» Element=xlsread('Truss.xlsx','input','E8:J42');
» for j=1:NE
»     i=Element(j,1);
»     E(i)=Element(j,2);
»     A(i)=Element(j,3);
»     Dir(i,1)=i;
»     Dir(i,2)=Element(j,4);
»     Dir(i,3)=Element(j,5);
» end
» %Load and Support detail
» NS=xlsread('Truss.xlsx','input','C3');
» Support=xlsread('Truss.xlsx','input','K8:L42');
» NL=xlsread('Truss.xlsx','input','C4');
» Forc=xlsread('Truss.xlsx','input','N8:P42');
»
» % Definition of Global stiffness submatrixes for each element:
» for i=1:NE
»     L(i)=sqrt((X(Dir(i,3))-X(Dir(i,2)))^2+(Z(Dir(i,3))-Z(Dir(i,2)))^2);
»     cos(i)=(X(Dir(i,3))-X(Dir(i,2)))/L(i);
»     sin(i)=(Z(Dir(i,3))-Z(Dir(i,2)))/L(i);
» end
» for i=1:NE
»     S(i)=E(i)*A(i)/L(i);
»     k11(:,:,i)=S(i)*[(cos(i))^2 sin(i)*cos(i);sin(i)*cos(i) (sin(i))^2];
»     k12(:,:,i)=-k11(:,:,i);
»     k21(:,:,i)=k12(:,:,i);
»     k22(:,:,i)=k11(:,:,i);
» end
» % Definition of structure stiffness matrix:
» K=zeros(2*NN,2*NN);
» for n=1:NE
»     i=Dir(n,2);
»     j=Dir(n,3);
»     K(2*i-1:2*i,2*i-1:2*i)=k11(:,:,n)+K(2*i-1:2*i,2*i-1:2*i);
»     K(2*i-1:2*i,2*j-1:2*j)=k12(:,:,n);
»     K(2*j-1:2*j,2*i-1:2*i)=k21(:,:,n);
»     K(2*j-1:2*j,2*j-1:2*j)=k22(:,:,n)+K(2*j-1:2*j,2*j-1:2*j);
» end
»
» % Definition of primary external nodal forces vector:
» F=zeros(2*NN,1);
» for i=1:NL
»     r=2*Forc(i,1);
»     F(r-1)=Forc(i,2);
»     F(r)=Forc(i,3);
» end
»
» % Elemination of rows and columns of K-matrix concern to support:
» S=K;
» for i=1:NS
»     r=2*Support(i,1);
»     if Support(i,2)==0
»         S(r-1,:)=0; S(:,r-1)=0; S(r-1,r-1)=1;
»         S(r,:)=0; S(:,r)=0; S(r,r)=1;
»     elseif Support(i,2)==1
»         S(r-1,:)=0; S(:,r-1)=0; S(r-1,r-1)=1;
»     else
»         S(r,:)=0; S(:,r)=0; S(r,r)=1;
»     end
» end
» %Solution of equation "{F}=[S]{d} by Gauss elimiantion method:
» n=2*NN;
» %Creation of upper triangular matrix
» s=0;
» for j=1:n-1
»     if S(j,j)==0
»         k=j;
»         for k=k+1:n
»             if S(k,j)==0
»                 continue
»             end
»             break
»         end
»         B=S(j,:); C=F(j);
»         S(j,:)=S(k,:); F(j)=F(k);
»         S(k,:)=B; F(k)=C;
»     end
»     for i=1+s:n-1
»         L=S(i+1,j)/S(j,j);
»         S(i+1,:)=S(i+1,:)-L*S(j,:);
»         F(i+1)=F(i+1)-L*F(j);
»     end
»     s=s+1;
» end
» %Solution of Equation:
» d=zeros(2*NN,1);
» d(n)=F(n)/S(n,n);
» for i=n-1:-1:1
»     sum=0;
»     for j=i+1:n
»         sum=sum+S(i,j)*d(j);
»     end
»     d(i)=(1/S(i,i))*(F(i)-sum);
» end
» %Creation of external nodal forces vector:
» W=K*d;
» %Calculation of elements axial force:
» for n=1:NE
»     i=Dir(n,2);
»     j=Dir(n,3);
»     PJ=k21(:,:,n)*[d(2*i-1);d(2*i)]+k22(:,:,n)*[d(2*j-1);d(2*j)];
»     P(n)=PJ(1)*cos(n)+PJ(2)*sin(n); % Axial Force in Element
»     stress(n)=P(n)/A(n); %Stress in element = Axial Force / Area
» end
»
»
» %Result Shown after running the script
»
» disp('<strong>           TRUSS CALCULATION USING MATLAB</strong>')
» disp('<strong>                 NUMBERICAL METHOD</strong>')
» disp('<strong>                 FINAL ASSIGNMENT</strong>')
» disp('__________________________________________________')
» disp(' ')
» disp('<strong>1. The Global Stiffness Matrixes [K] is:</strong>')
» K
»
» disp(' ')
» disp('<strong>2. Nodes horizontal and vertical displacement:</strong>')
» disp(' ')
» for i=1:NN
»     fprintf('Horizontal Displacement of Node\t %g\t',i); fprintf('is: %f ',1000*d(2*i-1)); fprintf('mm\n')
»     fprintf('Vertical Displacement of Node\t %g\t',i); fprintf('is: %f ',1000*d(2*i)); fprintf('mm\n')
»     disp(' ')
» end
»
» disp('------------------')
» disp(' ')
» disp('<strong>3. Horizontal and vertical reaction at supports:</strong>')
» disp(' ')
»
» for i=1:NS
»     r=2*Support(i,1);
»     if Support(i,2)==0
»         fprintf('Horizontal Reaction at Support\t %g\t',r/2); fprintf('is: %G ', W(r-1)); fprintf('kN\n')
»         fprintf('Vertical Reaction at Support\t %g\t',r/2); fprintf('is: %G ',W(r)); fprintf('kN\n')
»         disp(' ')
»     elseif Support(i,2)==1
»     fprintf('Horizontal Reaction at Support\t %g\t',r/2); fprintf('= %G\n',W(r-1));
»     else
»     fprintf('Vertical Reaction at Support\t%g\t',r/2); fprintf('= %G\n',W(r));
»     end
» end
»    
» disp(' ')
» disp('<strong>4. Stress in each element:</strong>')
» disp(' ')
» for i=1:NE
»     fprintf('Stress in Element %g ',i); fprintf('is: %f ',stress(i)); fprintf('kPa\n')
» end
 
SOLUTIONS SHOWN IN COMMAND WINDOW
AFTER RUNING THE SCRIPT IN MATLAB






Post a Comment

Previous Post Next Post