Skip to content

Commit 572fd19

Browse files
Add files via upload
1 parent aa403c1 commit 572fd19

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

TrussProgram.m

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
%This program presents a very simple problem
3+
% to solve truss problems
4+
%Written by: Mohammad Tawfik
5+
%Video explaining the code: https://youtu.be/2PnBDF9XxCs
6+
%Text about Finite Element Analysis:
7+
% https://www.researchgate.net/publication/321850256_Finite_Element_Analysis_Book_Draft
8+
%Book DOI: 10.13140/RG.2.2.32391.70560
9+
%
10+
%For the Finite Element Course and other courses
11+
% visit http://AcademyOfKnowledge.org
12+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13+
14+
clear all
15+
clc
16+
close all
17+
18+
%Problem Data
19+
EE=71e9;
20+
AA=0.01*0.01;
21+
NN=6;
22+
NE=9;
23+
24+
% X,Y,Fx,Fy, u, v
25+
Nodes=[0 ,0 ,0 ,0 ,1 ,2 ;
26+
2.0 ,0 ,0 ,0 ,3 ,4 ;
27+
2.5 ,0.5*sqrt(3),-100,0 ,5 ,6 ;
28+
1.5 ,0.5*sqrt(3),0 ,0 ,7 ,8 ;
29+
0.5 ,0.5*sqrt(3),0 ,0 ,9 ,10;
30+
1.0 ,0 ,0 ,0 ,11 ,12];
31+
32+
% Node#1, Node#2, Modulus of Elasticity , Area
33+
Elements=[1 ,5 ,EE ,AA;
34+
1 ,6 ,EE ,AA;
35+
5 ,4 ,EE ,AA;
36+
4 ,3 ,EE ,AA;
37+
6 ,2 ,EE ,AA;
38+
2 ,3 ,EE ,AA;
39+
2 ,4 ,EE ,AA;
40+
6 ,4 ,EE ,AA;
41+
6 ,5 ,EE ,AA];
42+
43+
BCs=[1,2,4]; %Fixed degrees of freedom
44+
%Creating Empty Global matrix and force vector
45+
KGlobal=zeros(2*NN, 2*NN);
46+
FGlobal=zeros(2*NN,1);
47+
48+
%Looping on all elements
49+
for ii=1:NE
50+
%Identifying the current element nodes and data
51+
Node1=Elements(ii,1);
52+
Node2=Elements(ii,2);
53+
Stiff=Elements(ii,3);
54+
Area=Elements(ii,4);
55+
%Getting the nodes' coordinates
56+
x1=Nodes(Node1,1);
57+
x2=Nodes(Node2,1);
58+
y1=Nodes(Node1,2);
59+
y2=Nodes(Node2,2);
60+
%Getting the nodes' degrees of freedom
61+
u1=Nodes(Node1,5);
62+
v1=Nodes(Node1,6);
63+
u2=Nodes(Node2,5);
64+
v2=Nodes(Node2,6);
65+
UV=[u1,v1,u2,v2];
66+
%Creating the stiffness matrix of each element
67+
LL=sqrt((x2-x1)^2+(y2-y1)^2); %Element length
68+
CC=(x2-x1)/LL; %Cos(Theta)
69+
SS=(y2-y1)/LL; %Sin(Theta)
70+
%Rotation MAtrix
71+
TT(:,:,ii)=[CC,-SS,0 ,0 ;
72+
SS,CC ,0 ,0 ;
73+
0 ,0 ,CC,-SS;
74+
0 ,0 ,SS,CC];
75+
%Element stiffness matrix in local coordinates
76+
Kl=[1,0,-1,0; 0,0,0,0; -1,0,1,0; 0,0,0,0]*Stiff*Area/LL;
77+
%Element stiffness matrix in GLOBAL coordinates
78+
KK(:,:,ii)=TT(:,:,ii)'*Kl*TT(:,:,ii);
79+
%Assembling the global stiffness matrix
80+
KGlobal(UV,UV)=KGlobal(UV,UV)+KK(:,:,ii);
81+
end
82+
%Filling the global force vector from nodes' data
83+
for ii=1:NN
84+
FGlobal(Nodes(ii,5))=Nodes(ii,3);
85+
FGlobal(Nodes(ii,6))=Nodes(ii,4);
86+
end
87+
88+
%Separating Auxiliary equations
89+
KAux=KGlobal(BCs,:);
90+
KAux(:,BCs)=[];
91+
%Getting reduced stiffness and force vector
92+
% by applying boundary conditions
93+
KReduced=KGlobal;
94+
KReduced(BCs,:)=[];
95+
KReduced(:,BCs)=[];
96+
FReduced=FGlobal;
97+
FReduced(BCs)=[];
98+
99+
%Solving for the displacements
100+
Displacements=KReduced\FReduced
101+
%Evaluating the reactions from the auxiliary equations
102+
Reactions=KAux*Displacements
103+
104+
%To obtain the element forces ...
105+
BCsC=[1:2*NN]'; %Complementary boundary conditions
106+
BCsC(BCs)=[];
107+
Displ=zeros(2*NN,1);
108+
%Storing the resulting displacements in their respective location
109+
Displ(BCsC)=Displacements;
110+
111+
%Looping on the elements
112+
for ii=1:NE
113+
Node1=Elements(ii,1);
114+
Node2=Elements(ii,2);
115+
u1=Nodes(Node1,5);
116+
v1=Nodes(Node1,6);
117+
u2=Nodes(Node2,5);
118+
v2=Nodes(Node2,6);
119+
UV=[u1,v1,u2,v2];
120+
%Evaluating the loval force vector
121+
ff(:,ii)=TT(:,:,ii)*KK(:,:,ii)*Displ(UV);
122+
end
123+
%Element foces are tension when f1 is negative
124+
ElementForces=-ff(1,:)'

0 commit comments

Comments
 (0)