Department of Civil, Structural and Environmental Engineering
Department of Civil, Structural and Environmental Engineering
Department of Civil, Structural and Environmental Engineering
Environmental Engineering
Student signature
Module S2
I have read and I understand the plagiarism provisions in the General Regulations of
the University Calendar for the current year, found at: http://www.tcd.ie/calendar
I have also completed the Online Tutorial on avoiding plagiarism Ready, Steady,
Write, located at http://tcd-ie.libguides.com/plagiarism/ready-steady-write
I declare that the assignment being submitted represents my own work and has not
been taken from the work of others save where appropriately referenced in the body
of the assignment.
Signed Date
Table of Contents
1. Introduction .......................................................................................................................... 1
1.1. FEM ............................................................................................................................... 1
ii
List of Figures
Figure 1: Beam example.............................................................................................................. 18
Figure 2: Shear, moment and deflection graphs of the example beam. .................................... 21
Figure 3: Beam on elastic foundation example. ......................................................................... 31
Figure 4: FDM solution diagrams. ............................................................................................... 33
Figure 5: Analytical solution diagrams ........................................................................................ 34
Figure 6: SAP200 solution diagrams............................................................................................ 34
Figure 7: Phi values for the rectangular shaft. ............................................................................ 39
Figure 8: Displacement vs time plots for a free vibration SDOF system. .................................... 42
Figure 9: Modes of the SDOF system. ......................................................................................... 44
iii
1. Introduction
This report presents the description of the work carried out within the S2 Advanced Structural
Analysis Course along with the MATLAB codes generated. Three main structural analysis
methods were studied and applied:
1. Finite Elements Method (FEM)
2. Finite Difference Method (FDM)
3. Stepping Methods, in this case, Runge-Kutta Method.
Description of the process is given in the following points.
1.1. FEM
The FEM programs were developed following the book of Kassimali (Kassimali, 1999). In this
book the author develops 6 different programs in order to solve 6 different types of structures
which are:
1. Plane trusses.
2. Beams.
3. Plane frames.
4. Space trusses.
5. Grids.
6. Space frames.
Starting for the simplest formulation to solve plane trusses and escalating in complexity until
attain the solution of space frames, 6 different programs were developed. All of them are
general, capable of generate and automatically assemble the global stiffness matrix from
geometrical and material member properties provided by the user. Different types of load are
handle for the programs, among them, uniformly distributed loads and nodal point loads.
For the specific case of the beam program, the Euler beam element was used and the structural
actions such as moments, shears x axial forces and deflections are described with the use of
shape functions corresponding to each type of structural element.
1.2. FDM
The FDM was applied two solve two different engineering problems:
1. Beam on an elastic foundation.
2. Torsion of non-circular prismatic sections.
General guidance was taken from Nevilles book (Ghali, 2009) to program the FDM. The first
problem was also solved using the analytical solution provided by Hetny (Hetnyi, 1946) in order
to compare the results with those obtained with the FDM and see how the discretization of the
problem influences in the final results. A third set of results was obtained using the commercial
1
software called SAP2000. All results and comparison between them is presented in further
chapters of this report.
For the second problem a simple rectangular section was used and in order to solve the system
of equation the advantages provided by MATLAB where exploded. In this case the use of \
provided the searched results in an efficient way and there was no need to implement the
Gauss-Seidel relaxation solution scheme. Same operator was used to solve all other system of
equations in the different methods studied.
2
2. Beam finite element code
In this chapter the program to solve plane trusses is presented and explained in detail. The other
5 programs to solve the corresponding structure types are presented in the annexes and follow
the same logic.
First of all, the program is divided in three main modules:
1. Input module
2. Analysis module
3. Results module
Comment lines in MATLAB code are preceded by a % symbol and are in red colour. They were
introduced in order to document the actual code lines and as a reminder for future access to the
codes.
*Note: the present example shows the values correspondent to the truss shown in Figure 4.2 of
the mentioned reference and the results obtained with the developed code match those
presented for the author.
The first line is common to all programs generated and is used to erase any possible existing
variables, close all figures and clean the command window.
This is the beginning of the Input module. Here the users can introduce all the necessary
information regarding, nodal coordinates, member connectivity and properties as well as the
loads acting in the structure and the supports.
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
The joint data is stored in a matrix called COORD. It contains both the X and Y global
coordinates of all the members of the truss. The number of lines of COORD is equivalent to the
number of nodes of the structure, NJ.
%Joint data
%COORD=[X Y]
COORD=[0 0;
288 0;
576 0;
864 0;
288 216;
576 216];
3
[NJ x]=size(COORD);
The support data is stored in a matrix called MSUP. The first column of this matrix contain the
joint number that is supported, NS, and the second and third columns contain the support
condition of the respective joint. A number 1 represents a restrained coordinate and a number
0 a free coordinate. A plane truss has two coordinates per node, translation in X and Y
directions.
%Support data
%MSUP=[NS TX TY]
MSUP=[1 1 1;
3 0 1;
4 0 1];
[NS x]=size(MSUP);
Since this is a linear elastic problem, only the modulus of Young is required to describe the
behaviour of the different materials of the structure. Each different modulus is stored in the
different rows of the vector called EM. The number of different materials is equivalent to the
length of the EM vector and is identified with NMP.
%EM=[E]
EM=[29000;
10000];
NMP=length(EM);
Since a truss element only carries axial forces, the only geometrical property required to
describe its stress condition is the cross sectional area. The values of the different elements
are stored in a vector called CP. The number of different sections is equivalent to the length of
the CP vector and is identified with a variable called NCP.
%CP=[A]
CP=[8;
12;
16];
NCP=length(CP);
The creation of the matrix MPRP is necessary in order to describe the member connectivity
and to assign their correspondent material and cross-sectional property. The first column of
this matrix contain the initial node of each element, NB, the second column contain the final
4
node of each element, NE, the third column specifies the material type of each element with
reference to the place that it occupies in the rows of the EM vector and finally the forth
column contain the cross-sectional type of each element with reference to the place that it
occupies in the rows of the CP vector. The number of rows of the MPRP matrix correspond
with the number of elements of the structure and is assigned to the variable called NM.
%Member data
[NM x]=size(MPRP);
Since a plane truss only carries point loads applied to its nodes only Node loads are described
in this part of the code. Nevertheless, for more complex structures, such as beams, element
loads as well as node loads can be applied. For further information about it please consult the
mentioned reference.
To assign the loads to the structure first a vector needs to be created where the nodes under
an external force will be specified in each one of the rows of this vector, JP. After this, a matrix
is created, PJ, where the correspondent X and Y force components will be described in global
coordinates. The number of rows of this matrix is equivalent to the number of joints loaded,
NJL, and its number of columns correspond to the number of coordinates per node in a plane
truss structure, NCJT.
%Load data
%JP=[NN]
JP=[2;
5;
6];
%PJ=[FX FY]
PJ=[0 -75;
25 0;
0 -60];
[NJL NCJT]=size(PJ);
5
This is the last part of the Input module, the following code lines are part of the Analysis
module. This module is divided at its time in sections:
1. Assignment of structure coordinate numbers.
2. Generation of the structure stiffness matrix.
3. Formation of the joint load vector.
4. Solution of the linear equations system to obtain the node displacements.
5. Calculation of member forces and support reactions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
In order to assemble the structure stiffness matrix a technique called member code numbers
is used. This technique was first introduced by S. S. Tezcan, for more details consult (Kassimali,
1999).
The total number of coordinates of the structure can be obtained by multiplying the number of
nodes, NJ, times the number of coordinates per node, NCJT. The number of restrained
coordinates is obtained by counting the number of non-zero elements in the second and third
columns of the MSUP matrix. After this, obtaining the number of degrees of freedom, NDOF, is
relatively easy, all is needed to do is subtract the number of NR to the number of total
coordinates of the structure.
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
A vector called NSC is created in order to relate the structure coordinates to the local
coordinates of each node. This is the so called structure coordinate number vector.
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
while I<=NJ
ICOUNT=0;
I1=1;
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
6
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
In order to assemble the structure stiffness matrix, the following code lines perform an
iterative process throughout all the elements, first obtaining each individual member
properties from the Input module information, then calculating its global stiffness matrix and
finally storing the appropriate terms of that element matrix into the structure stiffness matrix.
The function MSTIFFG computes the elements global stiffness matrix and the function STORES
assemble the structure stiffness matrix using the structure coordinate numbers vector NSC.
Both functions are presented at the end of the explanation of the main program within the
present chapter.
7
%S = Structure stiffness matrix
GK=zeros(2*NCJT);
S=zeros(NDOF);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
%Call of MSTIFFG
GK=MSTIFFG(E,A,BL,CX,CY,GK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S);
IM=IM+1;
end
In order to assemble the joint load vector, the following code lines perform an iterative
process through the load data vectors provided by the user in the Input mode. It iterates NJL
(Number of joints loaded) times and assigns the correspondent joint loads to the joint load
vector using once again the information contained within the structure coordinate numbers
vector, NSC.
P=zeros(NDOF,1);
I=1;
while I<=NJL
I1=JP(I);
8
I2=(I1-1)*NCJT;
J=1;
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
end
Since MATLAB is especially useful to work with matrices, it has a series of functions and
operators predefined that provide fast and efficient results. One of those is the \ operator
which provides the solution of a system of linear equations by writing only one code line thus
avoiding typing a whole routine or creating another function to apply Gauss, Gauss-Seidel or
any other solution process. By applying this operator, the free coordinate displacements of the
structures are determined using the structure stiffness matrix and the joint load vector
assembled in previous steps of the code.
d=S\P;
At this point of the program the initial problem has been solved. Once the displacements are
known, compatibility and equilibrium equations can be applied to determine member forces
and support reactions. Once again the program performs an iterative process passing
throughout each element, obtaining its properties from the Input module and computing with
the use of different functions the members global displacements vector, transformation
matrix, local displacements vector, local stiffness matrix, local force vector and global force
vector. Finally, the support reactions are computed by assigning the elements of this last
vector to their correspondent reaction vector position using once again the NSC vector.
The function MDISPG computes the member global displacements vector, MTRANS assembles
the member transformation matrix, MDISPL calculates the member local stiffness matrix,
MSTIFFL computes the member local stiffness matrix, MFORCEL calculates the member local
forces vector, MFORCEG provides the member global forces vector and finally STORER
assemble the structure support reactions vector. All functions are presented at the end of the
explanation of the main program within the present chapter.
%R = Reactions vector
%V = Global displacement vector
%T = Transformation matrix
%U = Local displacement vector
%F = Global force vector
%Q = Local force vector
%BK = Local stiffness matrix
%IM = Counters and flags
9
%MDISPG : Function that determines the member global displacement
vector V
%from the joint displacement vector P
%MTRANS : Function that forms the member transformation matrix T
%MDISPL : Function that calculates the member local displacement
vector U=T*V
%MSTIFFL : Function that forms the member local stiffness matrix BK
%MFORCEL : Function that evaluates the member local force vector
Q=BK*U
%it also creates the member axial force table to show in the results
%MFORCEG : Function that determines the member global force vector
F=T'*Q
%STORER : Function that stores the pertinent elements of the member
global
%force vector F in the reaction vector R
R=zeros(NR,1);
memaxifortab=zeros(NM,2);
memaxifortab(:,1)=(1:NM)';
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
V=zeros(2*NCJT,1);
T=zeros(2*NCJT);
U=zeros(2*NCJT,1);
BK=zeros(2*NCJT);
Q=zeros(2*NCJT,1);
F=zeros(2*NCJT,1);
%Call of MDISPG
V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V);
%Call of MTRANS
T=MTRANS(CX,CY,NCJT,T);
%Call of MDISPL
U=MDISPL(V,T,U);
10
%Call of MSTIFFL
BK=MSTIFFL(E,A,BL,BK);
%Call of MFORCEL
[Q memaxifortab]=MFORCEL(BK,U,IM,memaxifortab);
%Call of MFORCEG
F=MFORCEG(T,Q);
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,F,R);
IM=IM+1;
end
At this point all the information of interest when a structural problem is solved has been
already obtained. The last module of the program, the Results Module, presents in a graphical
way the mentioned numerical values and plots of the original geometry and the deformed
shape of the structures due to the applied set of loads.
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP]';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
11
fprintf('\n\t\t Joint Coordinates \n\n');
fprintf('Joint No \tX Coordinate \tY Coordinate \n');
fprintf('\t%g \t\t\t%g \t\t\t%g \n',COORD_table);
fprintf('\n\t\t\t Supports \n\n');
fprintf('\t*1 represents a constraint\n\n');
fprintf('Joint No \tX Restraint \tY Restraint \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \n',MSUP_table);
fprintf('\n\t\t Material Properties \n\n');
fprintf('Material No \tModulus of Elasticity (E) \n');
fprintf('\t%g \t\t\t\t\t%g \n',EM_table);
fprintf('\n\t Cross-Sectional Properties \n\n');
fprintf('\t\tProperty No \tArea (A) \n');
fprintf('\t\t\t%g \t\t\t\t%g \n',CP_table);
fprintf('\n\t\t\t\t\t\t Member Data \n\n');
fprintf('Member No \tBeginning Joint \tEnd Joint \tMaterial No
\tCross-Sectional Property No \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t\t\t%g
\n',MPRP_table);
fprintf('\n\t\t\t Joint Loads \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \n',JPPJ_table);
fprintf('\n\t\t\t End of Input Data \n\n');
fprintf('\n\n\t\t\t Results of analysis \n');
fprintf('\n\t\t\t Joint Displacements \n\n');
fprintf('Joint No \t\tX Translation \t\t\tY Translation \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \n',joidistab');
fprintf('\n\t\t\t Member Axial Forces \n\n');
fprintf('\t\t *Values < 0 represent Tension \n\n');
fprintf('\t\t\tMember \t\tAxial Force \n');
fprintf('\t\t\t\t%g \t\t\t%g \n',memaxifortab');
fprintf('\n\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tX Force \t\t\tY Force \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \n',supreatab');
fprintf('\n\t\t\t\t End of Analysis \n\n');
%Figures
IM=1;
while IM<=NM
%Undeformed geometry
JB=MPRP(IM,1);
JE=MPRP(IM,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
x1=[XB;XE];
y1=[YB;YE];
figure(1)
hold on
plot(x1,y1,'-o')
%Deformed geometry
12
ampfac=100;
XBD=XB+joidistab(JB,2)*ampfac;
XED=XE+joidistab(JE,2)*ampfac;
YBD=YB+joidistab(JB,3)*ampfac;
YED=YE+joidistab(JE,3)*ampfac;
x2=[XBD;XED];
y2=[YBD;YED];
plot(x2,y2,'r--x')
IM=IM+1;
end
A few remarks need to be make at this point. Even though the code presented and explained
in this report is the one for solving Plane trusses, the rest of the programs are structured and
work in a similar way, but, as said at the beginning of the chapter, increase in complexity. The
codes for plane trusses, space trusses, beams and plane frames provide numerical and
graphical results of the problem, nevertheless, the plane frame code can only provide correct
plots of element forces and deflections for horizontal elements. The two more complex codes
for grids and space frames can only provide numerical results, lack of time prevented further
code development in order to obtain accurate graphical representations for this las two types
of structures as well as for vertical and inclined elements in the plane frames code.
function GK=MSTIFFG(E,A,BL,CX,CY,GK)
%E = Young modulus
%A = Cross-section area
%BL = Length
%CX = Cosine
%CY = Sine
%GK = Global stiffness matrix
%Z, Z1, Z2, Z3 = Intermediate calculations
Z=(E*A)/BL;
Z1=Z*CX^2;
Z2=Z*CY^2;
Z3=Z*CX*CY;
13
%stiffness matrix GK in the structure stiffness matrix S
function S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S)
I=1;
while I<=2*NCJT
if I<=NCJT
I1=(JB-1)*NCJT+I;
N1=NSC(I1);
else I1=(JE-1)*NCJT+(I-NCJT);
N1=NSC(I1);
end
if N1<=NDOF
J=1;
while J<=2*NCJT
if J<=NCJT
I1=(JB-1)*NCJT+J;
N2=NSC(I1);
else I1=(JE-1)*NCJT+(J-NCJT);
N2=NSC(I1);
end
if N2<=NDOF
S(N1,N2)=S(N1,N2)+GK(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
else I=I+1;
end
end
function V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V)
14
%JE = Final node
%NCJT = Number of coordinates per joint
%NDOF = Number of degrees of freedom
%NSC = Structure coordinate number vector
%d = Joint displacements vector
%I, J, N = Counters and flags
I=1;
J=(JB-1)*NCJT;
while I<=NCJT
J=J+1;
N=NSC(J);
if N<=NDOF
V(I)=d(N);
I=I+1;
else I=I+1;
end
end
I=NCJT+1;
J=(JE-1)*NCJT;
while I<=2*NCJT
J=J+1;
N=NSC(J);
if N<=NDOF
V(I)=d(N);
I=I+1;
else I=I+1;
end
end
function T=MTRANS(CX,CY,NCJT,T)
%CX = Cosine
%CY = Sine
%NCJT = Number of coordinates per joint
%T = Transformation matrix
T=[CX CY 0 0;
-CY CX 0 0;
0 0 CX CY;
0 0 -CY CX];
15
%MDISPL : Function that calculates the member local displacement
vector U=T*V
function U=MDISPL(V,T,U)
U=T*V;
function BK=MSTIFFL(E,A,BL,BK)
%E = Young modulus
%A = Cross-section area
%BL = Length
%Z = Intermediate calculations
Z=(E*A)/BL;
BK=[Z 0 -Z 0;
0 0 0 0;
-Z 0 Z 0;
0 0 0 0];
memaxifortab(IM,2)=Q(1);
16
%MFORCEG : Function that determines the member global force vector
F=T'*Q
function F=MFORCEG(T,Q)
%T = Transformation matrix
%F = Global force vector
%Q = Local force vector
function R=STORER(JB,JE,NCJT,NDOF,NSC,F,R)
I=1;
while I<=2*NCJT
if I<=NCJT
I1=(JB-1)*NCJT+I;
N=NSC(I1);
else I1=(JE-1)*NCJT+(I-NCJT);
N=NSC(I1);
end
if N>NDOF
R(N-NDOF)=R(N-NDOF)+F(I);
I=I+1;
else I=I+1;
end
end
In order to show the results of the developed code the beam example presented in Kassimalis
Figure 5.19 was solved. This example was selected thus a comparison could be make between
the results presented in the reference and the results obtained and therefore the code could be
verified. The problem is shown in Figure 1.
17
Figure 1: Beam example.
The output of the code is shown in the following lines. It presents the information of both the
Input and the Results modules:
Joint Coordinates
Joint No X Coordinate
1 0
2 120
3 360
4 480
Supports
*1 represents a constraint
18
3 1 0
4 1 1
Material Properties
Cross-Sectional Properties
Member Data
Joint Loads
Member Loads
Member No Load Type Magnitude (W, M, w or w1) Magnitud (w2) Distance l1 Distance l2
2 3 0.1667 0 0 120
2 1 25 0 180 0
3 4 0.25 0 0 0
Results of analysis
Joint Displacements
19
Joint No Y Translation Rotation (Rad)
1 0 -5.571925e-04
2 0 -1.723053e-03
3 0 1.623819e-03
4 0 0.000000e+00
Support reactions
End of Analysis
And finally shear, moment and deflection graphs are shown in Figure 2. The results obtained
with the MATLAB code are practically identical to those presented in the reference. The
graphical representation of the results can definitely be improved in further coding,
unfortunately that is something that goes beyond the scope of this assignment.
20
Figure 2: Shear, moment and deflection graphs of the example beam.
21
3. Finite difference code
Unfortunately, the FDM code developed is not of general application. It is limited to certain load
types and support conditions due to limitations in the analytical equations of the problem
implemented on it. In order to be able to carry out a comparison of the results obtained by three
different ways; Analytical solution, FDM and commercial software SAP2000, the case of a simple
beam on elastic foundation with free ends and a uniformly distributed load all along its length
was solved and presented in this report. Regardless of the present limitations of the code, other
support and load types could be implemented as well as multiple elements with slight
modifications.
First of all, the code will be described and results will be presented in further points of the report.
The code is divided in five main modules:
1. Input module
2. Analytical solution module
3. FDM solution module
4. Results module
5. Figures module
As for the FEM code, the comment lines, code lines and text colours apply in a similar way. The
first code line is used to delete all existing variables, close all open figures and clean the
command screen in MATLAB.
In the input module the user has to introduce all the necessary information to define the
problem. It includes the basic parameters such as:
Modulus of elasticity of the material.
Modulus of elasticity of the foundation.
Beam length.
Beams dimensions.
Load matrix
Using this basic information, the code will proceed to compute the value of some other
fundamental parameters such as:
Winklers constant.
Bending stiffness.
Characteristic of the system.
22
Relative stiffness of the beam.
%% Input module
%Basic parameters
E=3e7;
k0=50000;
l=10;
b=1.1;
h=.5;
%Load matrix
[NL x]=size(LOAMAT);
%Wikler's constant
k=k0*b;
%I = Inertia
%EI = Bending stiffness
%alpha = Characteristic of the system
%al = Relative stiffness of the beam
I=b*h^3/12;
EI=E*I;
alpha=(k/(4*EI))^(1/4);
al=alpha*l;
The analytical solution implemented in the code is the one that uses the so called Krilovs
functions. Initial parameters of such functions and final computation of deflexions, slopes,
moments, shears and reactions are computed in two different functions, INIPAR and ALLPAR
respectively. Both functions are presented at the end of the explanation of the main program
within the present chapter.
%Call of INIPAR
23
[inipar]=INIPAR(alpha,l,LOAMAT,NL);
%Call of ALLPAR
[x1,VV,PHIPHI,MM,QQ]=ALLPAR(inipar,k,EI,alpha,l,NL,LOAMAT);
RR=k*VV/EI;
The FDM solution is performed in a new function called FDMSOL. The input variables for this
function are the number of elements in which the beam will be discretized, NNFD, a vector of
X coordinates for each one of the new nodes of the beam, xfdm, the size of the new elements,
lam, the value of the uniform distributed load applied in the beam, qi, an auxiliary square
matrix with size NNFD and the properties of both materials, soil and beam, k and EI
respectively.
NNFD=10;
xfdm=linspace(0,l,NNFD);
lam=l/(NNFD-1);
qi=LOAMAT(1,2);
auxmat=zeros(NNFD);
[dfdm,mfdm,rfdm]=FDMSOL(NNFD,xfdm,lam,qi,auxmat,k,EI);
The results module groups and organise the results obtained in the two precedent modules. It
plots the numerical values in a tabulated way in the command window of the software.
%% Results module
MEMLOAD_table=LOAMAT';
SUMMARY_table=[];
i=1;
j=1;
while i<=length(x1)+1
if i==101
i=100;
else i=i;
24
end
SUMMARY_table(j,1)=x1(i);
SUMMARY_table(j,2)=VV(i);
SUMMARY_table(j,3)=PHIPHI(i);
SUMMARY_table(j,4)=MM(i);
SUMMARY_table(j,5)=QQ(i);
SUMMARY_table(j,6)=RR(i);
j=j+1;
i=i+10;
end
Finally, the figures module create plots for the different diagrams of interest. The analytical
solution allows to create deflection, slope, moment, shear and reaction diagrams whereas that
the FDM solution only allows to plot deflection moment and reactions.
%% Figures module
%FDM figures
figure(1)
hold on
subplot(3,1,1)
plot(xfdm,dfdm)
title('FDM solution diagrams')
ylabel('Deflection')
subplot(3,1,2)
plot(xfdm,mfdm)
ylabel('Moments')
subplot(3,1,3)
25
plot(xfdm,rfdm)
ylabel('Reactions')
xlabel('Beam length')
figure(2)
hold on
subplot(5,1,1)
plot(x1,VV)
grid on
title('Analytical solution diagrams')
ylabel('Deflection')
subplot(5,1,2)
plot(x1,PHIPHI)
grid on
ylabel('Slope')
subplot(5,1,3)
plot(x1,MM)
grid on
ylabel('Moment')
subplot(5,1,4)
plot(x1,QQ)
grid on
ylabel('Shear')
subplot(5,1,5)
plot(x1,RR)
grid on
ylabel('Reaction')
xlabel('Beam length')
function [inipar]=INIBARPAR(alpha,l,LOAMAT,NL)
M0=0;
Q0=0;
syms x
Aax=cosh(alpha*x)*cos(alpha*x);
Bax=(cosh(alpha*x)*sin(alpha*x)+sinh(alpha*x)*cos(alpha*x))/2;
Cax=(sinh(alpha*x)*sin(alpha*x))/2;
Dax=(cosh(alpha*x)*sin(alpha*x)-sinh(alpha*x)*cos(alpha*x))/4;
26
Aal=eval(subs(Aax,l));
Bal=eval(subs(Bax,l));
Cal=eval(subs(Cax,l));
Dal=eval(subs(Dax,l));
K=[4*alpha^2*Cal 4*alpha*Dal;
4*alpha^3*Bal 4*alpha^2*Cal];
P=zeros(2,1);
inipar=zeros(4,1);
i=1;
while i<=NL
if LOAMAT(i,1)==1
f=l-LOAMAT(i,3);
F=LOAMAT(i,2);
Daf=eval(subs(Dax,f));
Caf=eval(subs(Cax,f));
Baf=eval(subs(Bax,f));
Aaf=eval(subs(Aax,f));
Vbarx=Daf*F/alpha^3;
PHIbarx=Caf*F/alpha^2;
Mbarx=-Baf*F/alpha;
Qbarx=-Aaf*F;
P=P+[Mbarx Qbarx]';
i=i+1;
else if LOAMAT(i,1)==2
m=l-LOAMAT(i,3);
M=LOAMAT(i,2);
Cam=eval(subs(Cax,m));
Bam=eval(subs(Bax,m));
Aam=eval(subs(Aax,m));
Dam=eval(subs(Dax,m));
Vbarx=-Cam*M/alpha^2;
PHIbarx=-Bam*M/alpha;
Mbarx=Aam*M;
Qbarx=-4*alpha*Dam*M;
P=P+[Mbarx Qbarx]';
i=i+1;
else if LOAMAT(i,1)==3
n=l-LOAMAT(i,3);
k=l-LOAMAT(i,4);
q=LOAMAT(i,2);
27
Aan=eval(subs(Aax,n));
Aak=eval(subs(Aax,k));
Dan=eval(subs(Dax,n));
Dak=eval(subs(Dax,k));
Can=eval(subs(Cax,n));
Cak=eval(subs(Cax,k));
Ban=eval(subs(Bax,n));
Bak=eval(subs(Bax,k));
Vbarx=(-q/(4*alpha^4))*(Aan-Aak);
PHIbarx=(q/alpha^3)*(Dan-Dak);
Mbarx=(-q/alpha^2)*(Can-Cak);
Qbarx=(-q/alpha)*(Ban-Bak);
P=P+[Mbarx Qbarx]';
i=i+1;
end
end
end
end
d=K\-P;
inipar=[d;
M0;
Q0];
function [x1,VV,PHIPHI,MM,QQ]=ALLPAR(inipar,k,EI,alpha,l,NL,LOAMAT)
syms x
Aax=cosh(alpha*x)*cos(alpha*x);
Bax=(cosh(alpha*x)*sin(alpha*x)+sinh(alpha*x)*cos(alpha*x))/2;
Cax=(sinh(alpha*x)*sin(alpha*x))/2;
Dax=(cosh(alpha*x)*sin(alpha*x)-sinh(alpha*x)*cos(alpha*x))/4;
x1=linspace(0,l);
i=1;
28
while i<=length(x1)
Aax1=eval(subs(Aax,x1(i)));
Bax1=eval(subs(Bax,x1(i)));
Cax1=eval(subs(Cax,x1(i)));
Dax1=eval(subs(Dax,x1(i)));
barpar=zeros(4,1);
ii=1;
while ii<=NL
if LOAMAT(ii,1)==1
F=LOAMAT(ii,2);
if x1(i)<LOAMAT(ii,3)
ii=ii+1;
else
f=x1(i)-LOAMAT(ii,3);
Daf=eval(subs(Dax,f));
Caf=eval(subs(Cax,f));
Baf=eval(subs(Bax,f));
Aaf=eval(subs(Aax,f));
Vbar=Daf*F/alpha^3;
PHIbar=Caf*F/alpha^2;
Mbar=-Baf*F/alpha;
Qbar=-Aaf*F;
ii=ii+1;
end
else if LOAMAT(ii,1)==2
M=LOAMAT(ii,2);
if x1(i)<LOAMAT(ii,3)
ii=ii+1;
else
m=x1(i)-LOAMAT(ii,3);
29
Cam=eval(subs(Cax,m));
Bam=eval(subs(Bax,m));
Aam=eval(subs(Aax,m));
Dam=eval(subs(Dax,m));
Vbar=-Cam*M/alpha^2;
PHIbar=-Bam*M/alpha;
Mbar=Aam*M;
Qbar=-4*alpha*Dam*M;
ii=ii+1;
end
else if LOAMAT(ii,1)==3
q=LOAMAT(ii,2);
if x1(i)<LOAMAT(ii,3)
ii=ii+1;
n=x1(i)-LOAMAT(ii,3);
k=0;
Aan=eval(subs(Aax,n));
Aak=eval(subs(Aax,k));
Dan=eval(subs(Dax,n));
Dak=eval(subs(Dax,k));
Can=eval(subs(Cax,n));
Cak=eval(subs(Cax,k));
Ban=eval(subs(Bax,n));
Bak=eval(subs(Bax,k));
Vbar=(-q/(4*alpha^4))*(Aan-Aak);
PHIbar=(q/alpha^3)*(Dan-Dak);
Mbar=(-q/alpha^2)*(Can-Cak);
Qbar=(-q/alpha)*(Ban-Bak);
ii=ii+1;
else if LOAMAT(ii,4)<=x1(i)
n=x1(i)-LOAMAT(ii,3);
k=x1(i)-LOAMAT(ii,4);
Aan=eval(subs(Aax,n));
Aak=eval(subs(Aax,k));
Dan=eval(subs(Dax,n));
Dak=eval(subs(Dax,k));
Can=eval(subs(Cax,n));
Cak=eval(subs(Cax,k));
Ban=eval(subs(Bax,n));
Bak=eval(subs(Bax,k));
Vbar=(-q/(4*alpha^4))*(Aan-Aak);
PHIbar=(q/alpha^3)*(Dan-Dak);
30
Mbar=(-q/alpha^2)*(Can-Cak);
Qbar=(-q/alpha)*(Ban-Bak);
ii=ii+1;
end
end
end
end
end
end
end
d=K*inipar+barpar;
VV(i)=d(1);
PHIPHI(i)=d(2);
MM(i)=d(3);
QQ(i)=d(4);
i=i+1;
end
x1;
VV;
PHIPHI;
MM;
QQ;
The beam of the example is a single spam beam supported on elastic foundation with a length
of 10 m. A uniform distributed load is applied all along its length. This is shown in Figure 3.
The output of the code is shown in the following lines. It presents the information of the Input,
Analytical solution and FDM solution modules:
31
General Structural Data
Member Loads
32
4.00 0.00363636 -4.83012e-13 200
5.00 0.00363636 -4.83012e-13 200
6.00 0.00363636 -7.24518e-13 200
7.00 0.00363636 -8.45271e-13 200
8.00 0.00363636 -4.83012e-13 200
9.00 0.00363636 3.62259e-13 200
10.00 0.00363636 0 200
And finally element and deflection graphs are shown in Figure 4, Figure 5 and Figure 6 for the
FDM, analytical and SAP2000 solutions respectively. The results obtained with the three
different ways show practically the same value of 200 kN/m for the reactions and 0.0036 m for
the deflections.
33
Figure 5: Analytical solution diagrams
The application of FDM to solve the problem of non-circular shafts was implemented following
the handouts of the course. The discretization of a rectangular section was performed
successfully and the values of the function were found. By integrating this values the total
torque, T, of the shaft was computed. Unfortunately, the developed code was not able to find
the values of shear due to a singularity of the equation system formed when the equations for
shear in the x and z direction were solved using the FDM. The developed code is presented in
the following lines as well as the graph of the values found in Figure 7. The value computed
for the torque is:
= 7.803 104
This torque value is meaningless in the since that the set-up of the problem was completely
random and we cannot conclude whether or not it is found within reasonable boundaries.
34
%Finite differences method
%Applied to solve torsion in a non-circular shaft
X=7;
Y=4;
%Other properties
%G = Shear modulus
%theta = Angular rotation
G=1000;
theta=1;
Nx=4;
Ny=4;
dx=X/Nx;
dy=Y/Ny;
NDOF=(Ny-1)*(Nx-1);
smat=zeros(NDOF);
k=1;
i=1;
while i<=Ny-1
j=1;
while j<=Nx-1
if i==1
if j==1
smat(k,i*j)=-(2/dx^2+2/dy^2);
smat(k,j+1)=1/dx^2;
smat(k,Nx)=1/dy^2;
j=j+1;
k=k+1;
else if j==Nx-1
smat(k,Nx-1)=-(2/dx^2+2/dy^2);
35
smat(k,Nx-2)=1/dx^2;
smat(k,(Nx-1)*2)=1/dy^2;
j=j+1;
k=k+1;
else
smat(k,j-1)=1/dx^2;
smat(k,j)=-(2/dx^2+2/dy^2);
smat(k,j+1)=1/dx^2;
smat(k,Nx-1+j)=1/dy^2;
j=j+1;
k=k+1;
end
end
else if i==Ny-1
if j==1
smat(k,(Nx-1)*(Ny-2)+1)=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*(Ny-2)+2)=1/dx^2;
smat(k,(Nx-1)*(Ny-3)+1)=1/dy^2;
j=j+1;
k=k+1;
else if j==Nx-1
smat(k,(Nx-1)*(Ny-1))=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*(Ny-1)-1)=1/dx^2;
smat(k,(Nx-1)*(Ny-2))=1/dy^2;
j=j+1;
k=k+1;
else
smat(k,(Nx-1)*(Ny-2)+j)=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*(Ny-2)+j-1)=1/dx^2;
smat(k,(Nx-1)*(Ny-2)+j+1)=1/dx^2;
smat(k,(Nx-1)*(Ny-3)+j)=1/dy^2;
j=j+1;
k=k+1;
end
end
else if i~=1 && i ~=Ny-1
if j==1
smat(k,(Nx-1)*(i-1)+1)=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*(i-1)+2)=1/dx^2;
smat(k,(Nx-1)*(i-2)+1)=1/dy^2;
smat(k,(Nx-1)*i+1)=1/dy^2;
j=j+1;
k=k+1;
else if j==Nx-1
smat(k,(Nx-1)*i)=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*i-1)=1/dx^2;
smat(k,(Nx-1)*(i-1))=1/dy^2;
smat(k,(Nx-1)*(i+1))=1/dy^2;
j=j+1;
k=k+1;
else if j~=1 && j~=Nx-1
smat(k,(Nx-1)*(i-1)+j)=-(2/dx^2+2/dy^2);
smat(k,(Nx-1)*(i-1)+j-1)=1/dx^2;
smat(k,(Nx-1)*(i-1)+j+1)=1/dx^2;
smat(k,(Nx-1)*(i-2)+j)=1/dy^2;
smat(k,(Nx-1)*i+j)=1/dy^2;
j=j+1;
k=k+1;
end
end
end
36
end
end
end
end
i=i+1;
end
forvec=ones(NDOF,1)*-2*G*theta;
phi=smat\forvec;
aux1=linspace(0,X,Nx+1);
aux2=linspace(0,Y,Ny+1);
aux3=zeros(Nx+1,Ny+1);
k=1;
i=1;
while i<=Ny-1
j=1;
while j<=Nx-1
aux3(1+i,1+j)=phi(k);
j=j+1;
k=k+1;
end
i=i+1;
end
figure(1)
surf(aux1,aux2,aux3)
xlabel('X axis')
ylabel('Y axis')
title('Values of phi')
%Torque computation
T=phi.*dx.*dy;
T=sum(T);
37
T=2*T;
%Shear stresses
phivec=aux3(:);
tauxzmat=zeros(length(phivec));
k=1;
i=1;
while i<=Ny+1
j=1;
while j<=Nx+1
if i==1
tauxzmat(k,Nx+j+1)=1/(2*dx);
j=j+1;
k=k+1;
else if i==Ny+1
tauxzmat(k,(Nx+1)*(Ny-1)+j)=-1/(2*dx);
j=j+1;
k=k+1;
else
tauxzmat(k,(Nx+1)*(i-2)+j)=-1/(2*dx);
tauxzmat(k,(Nx+1)*i+j)=1/(2*dx);
j=j+1;
k=k+1;
end
end
end
i=i+1;
end
tauxz=tauxzmat\phivec;
tauyzmat=zeros(length(phivec));
k=1;
i=1;
while i<=Ny+1
j=1;
while j<=Nx+1
if j==1
tauyzmat(k,(Nx+1)*(i-1)+1)=1/(2*dy);
j=j+1;
k=k+1;
else if j==Nx+1
tauyzmat(k,(Nx+1)*i)=-1/(2*dy);
j=j+1;
k=k+1;
38
else
tauyzmat(k,(Nx+1)*(i-1)+(j-1))=-1/(2*dy);
tauyzmat(k,(Nx+1)*(i-1)+(j+1))=1/(2*dy);
j=j+1;
k=k+1;
end
end
end
i=i+1;
end
tauyz=tauyzmat\phivec;
tau=(tauxz.^2+tauyz.^2).^.5;
39
4. Structural dynamics
The structural dynamics code is basically divided into two sections. The first one provides the
solution of a SDOF system using both the exact analytical solution and a numerical time-stepping
solution, Runge-Kutta.
First the initial properties of the system, mass, stiffness, time step and time vector as well as
damping coefficient, are provided by the user.
%% Runge-Kutta
%Differential equation
%m*x2+c*x1+k*x=0
m=4; %Mass
k=2000; %Stiffness
dt=.01; %Time step
t=0:dt:10; %Time vector
t=t';
psi=.1;
ccr=2*m*wn;
c=psi*ccr;
wd=wn*(1-psi^2)^.5;
%Analytical solution
u0=5;
u10=0;
The analytical solution is simply obtained by substituting the values of the time vector in the
next equation:
u=exp(-
psi.*wn.*t).*(u0.*cos(wd.*t)+((u10+u0.*psi.*wn)./wd).*sin(wd.*t));
The numerical solution on the other hand performs and iterative process for each time step in
order to compute the values for each time instant of displacement, velocity and acceleration.
% %Time stepping
40
x1=zeros(length(t),1); %Velocities vector
x2=zeros(length(t),1); %Accelerations vector
%Initial conditions
taux=zeros(4,1);
xaux=zeros(4,1);
x1aux=zeros(4,1);
x2aux=zeros(4,1);
taux(1)=t(1);
xaux(1)=5;
x1aux(1)=0;
x2aux(1)=0;
x(1)=xaux(1);
x1(1)=x1aux(1);
x2(1)=(-k*xaux(1)-c*x1aux(1))/m;
for i=2:length(t)
j=1;
while j<=4
if j==1
taux(j)=t(i-1);
xaux(j)=x(i-1);
x1aux(j)=x1(i-1);
x2aux(j)=(-k*xaux(j)-c*x1aux(j))/m;
j=j+1;
else if j==4
taux(j)=t(i-1)+dt;
xaux(j)=x(i-1)+x1aux(j-1)*dt;
x1aux(j)=x1(i-1)+x2aux(j-1)*dt;
x2aux(j)=(-k*xaux(j)-c*x1aux(j))/m;
j=j+1;
else
taux(j)=t(i-1)+dt/2;
xaux(j)=x(i-1)+x1aux(j-1)*dt/2;
x1aux(j)=x1(i-1)+x2aux(j-1)*dt/2;
x2aux(j)=(-k*xaux(j)-c*x1aux(j))/m;
j=j+1;
end
end
x(i)=x(i-
1)+(dt/6)*(x1aux(1)+2*x1aux(2)+2*x1aux(3)+x1aux(4));
x1(i)=x1(i-
1)+(dt/6)*(x2aux(1)+2*x2aux(2)+2*x2aux(3)+x2aux(4));
x2(i)=(-k*x(i-1)-c*x1(i-1))/m;
end
end
Finally, both set of values of displacement obtained in the two different ways are plotted
against time. The results are practically identical for both solution methods.
41
%Figures
figure(1)
subplot(2,1,1)
plot(t,u)
ylabel('Displacements, m')
xlabel('Time, s')
title('Analytical solution of a free vibration SDOF system')
subplot(2,1,2)
plot(t,x)
ylabel('Displacements, m')
xlabel('Time, s')
title('Runge-Kutta solution of a free vibration SDOF system')
The second part of the code provides the solution for a MDOF system. In this case a three story
structure was analysed. Mass was supposed to be lumped at each floor and hypothetical
values for the stiffness of the columns were used. The percentage damping and the stories
heights needs to be provided by the user as well.
%% Cantilever structure
%Input
stohig=[0,4,8,12]';
%Assembling of matrices
42
M=[m1 0 0;
0 m2 0;
0 0 m3]; %Mass matrix
K=[2*k1+2*k2 -2*k2 0;
-2*k2 2*k2+2*k3 -2*k3;
0 -2*k3 2*k3]; %Stiffness matrix
The natural frequencies and Eigen vectors of the system are computed. The Eigen vectors were
normalized with respect to the third floor of the system.
syms w2
w2mdof=solve(det(K-w2*M)==0,w2);
wmdof=sort(real(vpa(w2mdof.^.5)));
%Calculation of eigenvectors
%Normalization about the last DOF
eigvec=zeros(length(wmdof));
for i=1:length(wmdof)
auxvec=zeros(length(wmdof),1);
auxvec(length(wmdof))=1;
auxmat=K-wmdof(i)^2*M;
auxmat(length(wmdof),:)=0;
auxmat(length(wmdof),length(wmdof))=1;
eigvecaux=linsolve(auxmat,auxvec);
eigvec(:,i)=eigvecaux;
end
%Figures
plotaux= zeros(length(wmdof)+1,length(wmdof));
plotaux(2:length(wmdof)+1,:)=eigvec;
figure(2)
subplot(1,3,1)
plot(zeros(4,1)',stohig,plotaux(:,1),stohig)
ylabel('Storey High, m')
xlabel('Displacements, m')
title('Mode 1')
subplot(1,3,2)
plot(zeros(4,1)',stohig,plotaux(:,2),stohig)
ylabel('Storey High, m')
xlabel('Displacements, m')
title('Mode 2')
43
subplot(1,3,3)
plot(zeros(4,1)',stohig,plotaux(:,3),stohig)
ylabel('Storey High, m')
xlabel('Displacements, m')
title('Mode 3')
%% Modal analysis
44
5. Conclusions
Developing the codes to solve some of the most common structural engineering problems
presented on the everyday practice of an engineer is helpful in order to understand the
theoretical development and programming structure of some of the most used commercial
available software. Even though the scope of the codes presented in this report is very limited,
further developments can be carry out with slight or maybe more significant modifications, it
will depend on the aim of further work in the subject, to produce a more advanced and complete
structural analysis software package, thus the codes presented set the bases for the creation of
such engineering tool.
45
6. References
Ghali, A. (2009). Structural analysis : a unified classical and matrix approach (6th ed.). London:
Taylor & Francis.
Hetnyi, M. (1946). Beams on elastic foundation : theory with applications in the fields of civil and
mechanical engineering. Ann Arbor, Mich.: University of Michigan Press.
Kassimali, A. (1999). Matrix analysis of structures. Pacific Grove, CA ; London: Brooks/Cole.
46
7. Annexes
7.1. FEM Beam code
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Joint data
NCJT=2;
%COORD=[X]
COORD=[0;
5];
NJ=length(COORD);
%Support data
%MSUP=[NS TY RZ]
MSUP=[1 1 1;
2 1 1];
[NS x]=size(MSUP);
%EM=[E]
EM=[1.999e8];
NMP=length(EM);
%CP=[IZ]
47
CP=[6.572e-5];
NCP=length(CP);
%Member data
[NM x]=size(MPRP);
%Load data
%JP=[NN]
JP=[];
%PJ=[FY MZ]
PJ=[];
[NJL x]=size(PJ);
%MP=[NM LOADTYPE]
MP=[1 4];
[NML x]=size(PM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
48
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
while I<=NJ
ICOUNT=0;
I1=1;
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
49
%XB = X coordinate of initial node
%XE = X coordinate of final node
%BL = Length
%IM, IML, I = Counters and flags
S=zeros(NDOF);
P=zeros(NDOF,1);
BK=zeros(2*NCJT);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
ZI=CP(I);
XB=COORD(JB);
XE=COORD(JE);
BL=XE-XB;
%Call of MSTIFFL
BK=MSTIFFL(E,ZI,BL,BK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,BK,S);
if NML>0
QF=zeros(2*NCJT,1);
IML=1;
while IML<=NML
if IM==MP(IML,1)
50
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of STOREPF
P=STOREPF(JB,JE,NCJT,NDOF,NSC,QF,P);
IM=IM+1;
else IM=IM+1;
end
end
I=1;
while I<=NJL
I1=JP(I);
I2=(I1-1)*NCJT;
J=1;
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
end
d=S\P;
%R = Reactions vector
%U = Local displacement vector
%Q = Local force vector
%BK = Local stiffness matrix
51
%IM = Counters and flags
R=zeros(NR,1);
memendfortab=zeros(NM*2,4);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
ZI=CP(I);
XB=COORD(JB);
XE=COORD(JE);
BL=XE-XB;
U=zeros(2*NCJT,1);
BK=zeros(2*NCJT);
Q=zeros(2*NCJT,1);
%Call of MDISPL
U=MDISPL(JB,JE,NCJT,NDOF,NSC,d,U);
%Call of MSTIFFL
BK=MSTIFFL(E,ZI,BL,BK);
QF=zeros(2*NCJT,1);
if NML>0
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
52
else IML=IML+1;
end
end
%Call of MFORCEL
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
end
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,Q,R);
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP]';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
MEMLOAD_table=[MP PM]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
53
fprintf('\t*1 represents a constraint\n\n');
fprintf('Joint No \tY Restraint \tRotational Restraint \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \n',MSUP_table);
fprintf('\n\t\t Material Properties \n\n');
fprintf('Material No \tModulus of Elasticity (E) \n');
fprintf('\t%g \t\t\t\t\t%g \n',EM_table);
fprintf('\n\t Cross-Sectional Properties \n\n');
fprintf('\tProperty No \tMoment of Inertia (I) \n');
fprintf('\t\t%g \t\t\t\t\t%g \n',CP_table);
fprintf('\n\t\t\t\t\t\t Member Data \n\n');
fprintf('Member No \tBeginning Joint \tEnd Joint \tMaterial No
\tCross-Sectional Property No \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t\t\t%g
\n',MPRP_table);
fprintf('\n\t\t\t Joint Loads \n\n');
fprintf('Joint No \t\tY Force \t\tMoment \n');
fprintf('\t%g \t\t\t\t%g \t\t\t%g \n',JPPJ_table);
fprintf('\n\t\t\t Member Loads \n\n');
fprintf('Member No \tLoad Type \tMagnitude (W, M, w or w1) \tMagnitud
(w2) \tDistance l1 \tDistance l2\n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t\t%g \t\t\t\t%g
\t\t\t\t%g\n',MEMLOAD_table);
fprintf('\n\t\t\t End of Input Data \n\n');
fprintf('\n\n\t\t\t Results of analysis \n');
fprintf('\n\t\t\t Joint Displacements \n\n');
fprintf('Joint No \t\tY Translation \t\t\tRotation (Rad) \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%e \n',joidistab');
fprintf('\n\t\t Member End Forces in Local Coordinates\n\n');
fprintf('Member \t\tJoint \t\tShear Force \t\tMoment \n');
fprintf('\t%g \t\t%g \t\t\t%g \t\t\t%g\n',memendfortab');
fprintf('\n\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tY Force \t\t\tMoment \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \n',supreatab');
fprintf('\n\t\t\t\t End of Analysis \n\n');
%Figures
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
BL=XE-XB;
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
ZI=CP(I);
54
%Shape functions
x1=linspace(0,BL);
y1=zeros(length(x1),1);
%Deflection
N1DEF=1-3*(x1/BL).^2+2*(x1/BL).^3; %Shear 1
N2DEF=BL*(x1/BL-2*(x1/BL).^2+(x1/BL).^3); %Bending 1
N3DEF=3*(x1/BL).^2-2*(x1/BL).^3; %Shear 2
N4DEF=(x1.^2/BL).*(-1+x1/BL); %Bending 2
%Moment
N1MOM=E*ZI*(12*x1/BL^3-6/BL^2);
N2MOM=E*ZI*(BL*(6*x1/BL^3-4/BL^2));
N3MOM=E*ZI*(6/BL^2-12*x1/BL^3);
N4MOM=E*ZI*(-2*(BL-3*x1)/BL^2);
%Shear
N1SHE=E*ZI*(12/BL^3);
N2SHE=E*ZI*(6/BL^2);
N3SHE=E*ZI*(-12/BL^3);
N4SHE=E*ZI*(6/BL^2);
ampfac=1;
dd=[joidistab(JB,2) joidistab(JB,3) joidistab(JE,2)
joidistab(JE,3)]';
x2=x1+XB;
y2=y1'+N1DEF*dd(1)*ampfac+N2DEF*dd(2)*ampfac+N3DEF*dd(3)*ampfac+N4DEF*
dd(4)*ampfac;
%Shear diagrams
dia_she=zeros(1,length(x1));
dia_she=dia_she+N1SHE*dd(1)+N2SHE*dd(2)+N3SHE*dd(3)+N4SHE*dd(4);
%Moment diagrams
dia_mom=zeros(1,length(x1));
dia_mom=dia_mom+N1MOM*dd(1)+N2MOM*dd(2)+N3MOM*dd(3)+N4MOM*dd(4);
if NML>0
IML=1;
55
while IML<=NML
if IM==MP(IML,1)
[y2,dia_she,dia_mom]=MFEFLLDEF(dia_she,dia_mom,IML,BL,MP,PM,y2,x1,ampf
ac,E,ZI);
IML=IML+1;
else IML=IML+1;
end
end
end
%Undeformed geometry
y=zeros(NJ,1);
figure(1)
hold on
subplot(3,1,1)
plot(COORD,y,'-o')
hold on
plot(x2,dia_she,'r')
ylabel('Shear diagram')
hold on
subplot(3,1,2)
plot(COORD,y,'-o')
hold on
plot(x2,dia_mom,'r')
ylabel('Moment diagram')
hold on
subplot(3,1,3)
plot(COORD,y,'-o')
hold on
plot(x2,y2,'r')
xlabel('Element length')
ylabel('Deflection')
IM=IM+1;
end
56
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Joint data
NCJT=3;
%COORD=[X Y Z]
COORD=[0 0 0;
5 0 0];
[NJ x]=size(COORD);
%Support data
%MSUP=[NS TX TY RZ]
MSUP=[1 1 1 0;
2 0 1 0];
[NS x]=size(MSUP);
%EM=[E]
EM=[1.999e8];
NMP=length(EM);
%CP=[A IZ]
CP=[4.2653e-3 6.572e-5];
NCP=length(CP);
%Member data
57
MPRP=[1 2 1 1];
[NM x]=size(MPRP);
%Load data
%JP=[NN]
JP=[];
%PJ=[FX FY MZ]
PJ=[];
[NJL X]=size(PJ);
%MP=[NM LOADTYPE]
MP=[1 6];
[NML x]=size(PM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
while I<=NJ
ICOUNT=0;
I1=1;
58
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
59
%GK = Global stiffness matrix
%S = Structure stiffness matrix
%T = Transformation matrix
%QF = Fixed-end force vector
%P = Structure load vector
%FF = Member global fixed-end force vector
GK=zeros(2*NCJT);
S=zeros(NDOF);
BK=zeros(2*NCJT);
T=zeros(2*NCJT);
P=zeros(NDOF,1);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I,1);
ZI=CP(I,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
%Call of MSTIFFL
BK=MSTIFFL(E,A,ZI,BL,BK);
%Call of MTRANS
T=MTRANS(CX,CY,NCJT,T);
%Call of MSTIFFG
60
GK=MSTIFFG(BK,T,GK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S);
if NML>0
QF=zeros(2*NCJT,1);
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFEFG
FF=zeros(2*NCJT,1);
FF=MFEFG(T,QF,FF);
%Call of STOREPF
P=STOREPF(JB,JE,NCJT,NDOF,NSC,FF,P);
IM=IM+1;
else IM=IM+1;
end
end
I=1;
while I<=NJL
I1=JP(I);
I2=(I1-1)*NCJT;
J=1;
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
61
J=J+1;
else J=J+1;
end
end
I=I+1;
end
d=S\P;
%R = Reactions vector
%V = Global displacement vector
%U = Local displacement vector
%F = Global force vector
%Q = Local force vector
%IM = Counters and flags
R=zeros(NR,1);
memendfortab=zeros(NM*2,5);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I,1);
ZI=CP(I,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
62
CY=(YE-YB)/BL;
V=zeros(2*NCJT,1);
T=zeros(2*NCJT);
U=zeros(2*NCJT,1);
BK=zeros(2*NCJT);
Q=zeros(2*NCJT,1);
F=zeros(2*NCJT,1);
%Call of MDISPG
V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V);
%Call of MTRANS
T=MTRANS(CX,CY,NCJT,T);
%Call of MDISPL
U=MDISPL(V,T,U);
%Call of MSTIFFL
BK=MSTIFFL(E,A,ZI,BL,BK);
QF=zeros(2*NCJT,1);
if NML>0
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFORCEL
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
end
%Call of MFORCEG
63
F=MFORCEG(T,Q);
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,F,R);
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP']';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
MEMLOAD_table=[MP PM]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
64
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t\t\t%g
\n',MPRP_table);
fprintf('\n\t\t\t\t\t Joint Loads \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\tMoment \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \n',JPPJ_table);
fprintf('\n\t\t\t\t\t Member Loads \n\n');
fprintf('Member No \tLoad Type \tMagnitude (W, M, w or w1) \tMagnitud
(w2) \tDistance l1 \tDistance l2\n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t\t%g \t\t\t\t%g
\t\t\t\t%g\n',MEMLOAD_table);
fprintf('\n\t\t\t End of Input Data \n\n');
fprintf('\n\n\t\t\t Results of analysis \n');
fprintf('\n\t\t\t Joint Displacements \n\n');
fprintf('Joint No \t\tX Translation \t\t\tY Translation \t\t\tRotation
(Rad) \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t\t\t%e \n',joidistab');
fprintf('\n\t\t Member End Forces in Local Coordinates\n\n');
fprintf('Member \t\tJoint \t\tAxial Force \t\tShear Force \t\tMoment
\n');
fprintf('\t%g \t\t%g \t\t\t%g \t\t\t%g \t\t\t%g\n',memendfortab');
fprintf('\n\t\t\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\t\tMoment \n');
fprintf('\t%g \t\t\t%g \t\t\t%g \t\t\t\t%g \n',supreatab');
fprintf('\n\t\t\t\t End of Analysis \n\n');
%Figures
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I,1);
ZI=CP(I,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
%Shape functions
65
%x1 = Discretization vector of the member (100 points default)
x1=linspace(0,BL);
y1=zeros(length(x1),1);
%Deflection
N1DEF=1-x1/BL; %Axial 1
N2DEF=1-3*(x1/BL).^2+2*(x1/BL).^3; %Shear 1
N3DEF=BL*(x1/BL-2*(x1/BL).^2+(x1/BL).^3); %Bending 1
N4DEF=x1/BL; %Axial 2
N5DEF=3*(x1/BL).^2-2*(x1/BL).^3; %Shear 2
N6DEF=(x1.^2/BL).*(-1+x1/BL); %Bending 2
%Moment
N1MOM=E*ZI*(12*x1/BL^3-6/BL^2);
N2MOM=E*ZI*(BL*(6*x1/BL^3-4/BL^2));
N3MOM=E*ZI*(6/BL^2-12*x1/BL^3);
N4MOM=E*ZI*(-2*(BL-3*x1)/BL^2);
%Shear
N1SHE=E*ZI*(12/BL^3);
N2SHE=E*ZI*(6/BL^2);
N3SHE=E*ZI*(-12/BL^3);
N4SHE=E*ZI*(6/BL^2);
%Axial
N1AXI=-E*A/BL;
N2AXI=E*A/BL;
ampfac=1;
ampfacaxi=10;
dd=[joidistab(JB,2) joidistab(JB,3) joidistab(JB,4)
joidistab(JE,2) joidistab(JE,3) joidistab(JE,4)]';
x2=x1+XB+N1DEF*dd(1)*ampfacaxi+N4DEF*dd(4)*ampfacaxi;
y2=y1'+N2DEF*dd(2)*ampfac+N3DEF*dd(3)*ampfac+N5DEF*dd(5)*ampfac+N6DEF*
dd(6)*ampfac;
%Axial diagrams
dia_axi=zeros(1,length(x1));
dia_axi=dia_axi+N1AXI*dd(1)+N2AXI*dd(4);
%Shear diagrams
66
dia_she=zeros(1,length(x1));
dia_she=dia_she+N1SHE*dd(2)+N2SHE*dd(3)+N3SHE*dd(5)+N4SHE*dd(6);
%Moment diagrams
dia_mom=zeros(1,length(x1));
dia_mom=dia_mom+N1MOM*dd(2)+N2MOM*dd(3)+N3MOM*dd(5)+N4MOM*dd(6);
if NML>0
IML=1;
while IML<=NML
if IM==MP(IML,1)
[x2,y2,dia_she,dia_mom,dia_axi]=MFEFLLDEF(ampfacaxi,dia_axi,dia_she,di
a_mom,IML,BL,MP,PM,y2,x2,x1,ampfac,E,ZI,A);
IML=IML+1;
else IML=IML+1;
end
end
end
%Undeformed geometry
x=[XB;XE];
y=[YB;YE];
figure(1)
hold on
subplot(4,1,1)
plot(x,y,'-o')
hold on
plot(x2,dia_axi,'r')
ylabel('Axial diagram')
hold on
subplot(4,1,2)
plot(x,y,'-o')
hold on
plot(x2,dia_she,'r')
ylabel('Shear diagram')
hold on
subplot(4,1,3)
plot(x,y,'-o')
hold on
plot(x2,dia_mom,'r')
ylabel('Moment diagram')
67
hold on
subplot(4,1,4)
plot(x,y,'-o')
hold on
plot(x2,y2,'r')
xlabel('Element length')
ylabel('Deformation')
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Joint data
COORD=[-72 0 96;
144 0 96;
72 0 -96;
-144 0 -96;
0 288 0];
[NJ x]=size(COORD);
%Support data
MSUP=[1 1 1 1;
2 1 1 1;
3 1 1 1;
4 1 1 1];
[NS x]=size(MSUP);
EM=[10000];
68
NMP=length(EM);
CP=[8.4];
NCP=length(CP);
%Member data
MPRP=[1 5 1 1;
2 5 1 1;
3 5 1 1;
4 5 1 1];
[NM x]=size(MPRP);
%Load data
JP=[5];
[NJL NCJT]=size(PJ);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
69
while I<=NJ
ICOUNT=0;
I1=1;
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
70
%CX = X cosine
%CY = Y cosine
%CZ = Z cosine
%IM, I = Counters and flags
GK=zeros(2*NCJT);
S=zeros(NDOF);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
CZ=(ZE-ZB)/BL;
%Call of MSTIFFG
GK=MSTIFFG(E,A,BL,CX,CY,CZ,GK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S);
IM=IM+1;
end
P=zeros(NDOF,1);
I=1;
71
while I<=NJL
I1=JP(I);
I2=(I1-1)*NCJT;
J=1;
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
end
d=S\P;
%R = Reactions vector
%V = Global displacement vector
%T = Transformation matrix
%U = Local displacement vector
%F = Global force vector
%Q = Local force vector
%BK = Local stiffness matrix
%IM = Counters and flags
R=zeros(NR,1);
memaxifortab=zeros(NM,2);
memaxifortab(:,1)=(1:NM)';
IM=1;
while IM<=NM
72
%Evaluation of member properties
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
CZ=(ZE-ZB)/BL;
V=zeros(2*NCJT,1);
T=zeros(2,2*NCJT);
U=zeros(2,1);
BK=zeros(2,2);
Q=zeros(2,1);
F=zeros(2*NCJT,1);
%Call of MDISPG
V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V);
%Call of MTRANS
T=MTRANS(CX,CY,CZ,T);
%Call of MDISPL
U=MDISPL(V,T,U);
%Call of MSTIFFL
BK=MSTIFFL(E,A,BL,BK);
%Call of MFORCEL
[Q memaxifortab]=MFORCEL(BK,U,IM,memaxifortab);
%Call of MFORCEG
F=MFORCEG(T,Q);
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,F,R);
IM=IM+1;
end
73
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP]';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
74
fprintf('\t\t *Values < 0 represent Tension \n\n');
fprintf('\t\t\tMember \t\tAxial Force \n');
fprintf('\t\t\t\t%g \t\t\t%g \n',memaxifortab');
fprintf('\n\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tX Force \t\t\tY Force \t\t\tZ Force\n');
fprintf('\t%g \t\t\t\t%g \t\t\t%g \t\t\t%g\n',supreatab');
fprintf('\n\t\t\t\t End of Analysis \n\n');
%Figures
IM=1;
while IM<=NM
%Undeformed geometry
JB=MPRP(IM,1);
JE=MPRP(IM,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
x1=[XB;XE];
y1=[YB;YE];
z1=[ZB;ZE];
figure(1)
hold on
plot3(x1,y1,z1,'-o')
%Deformed geometry
ampfac=100;
XBD=XB+joidistab(JB,2)*ampfac;
XED=XE+joidistab(JE,2)*ampfac;
YBD=YB+joidistab(JB,3)*ampfac;
YED=YE+joidistab(JE,3)*ampfac;
ZBD=ZB+joidistab(JB,4)*ampfac;
ZED=ZE+joidistab(JE,4)*ampfac;
x2=[XBD;XED];
y2=[YBD;YED];
z2=[ZBD,ZED];
plot3(x2,y2,z2,'r--x')
xlabel('X axis');
ylabel('Y axis');
zlabel('Z axis');
IM=IM+1;
end
75
7.4. FEM Grids code
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Joint data
NCJT=3;
COORD=[0 0;
8 0;
0 6;
8 6];
[NJ x]=size(COORD);
%Support data
MSUP=[1 1 1 1;
2 1 1 1
3 1 1 1];
[NS x]=size(MSUP);
EM=[200e6 76e6];
[NMP x]=size(EM);
CP=[115e-6 347e-6];
[NCP x]=size(CP);
%Member data
76
%MPRP = Member data matrix
%NM = Number of members
MPRP=[1 4 1 1;
2 4 1 1;
3 4 1 1];
[NM x]=size(MPRP);
%Load data
JP=[];
PJ=[];
[NJL x]=size(PJ);
MP=[2 3;
3 3];
PM=[20 0 0 0;
20 0 0 0];
[NML x]=size(PM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
77
while I<=NJ
ICOUNT=0;
I1=1;
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
78
%CX = X cosine
%CZ = Z cosine
%IM, I = Counters and flags
GK=zeros(2*NCJT);
S=zeros(NDOF);
BK=zeros(2*NCJT);
T=zeros(2*NCJT);
P=zeros(NDOF,1);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I,1);
G=EM(I,2);
I=MPRP(IM,4);
J=CP(I,1);
ZI=CP(I,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
ZB=COORD(JB,2);
ZE=COORD(JE,2);
BL=((XE-XB)^2+(ZE-ZB)^2)^.5;
CX=(XE-XB)/BL;
CZ=(ZE-ZB)/BL;
%Call of MSTIFFL
BK=MSTIFFL(E,G,J,ZI,BL,BK);
79
%Call of MTRANS
T=MTRANS(CX,CZ,T);
%Call of MSTIFFG
GK=MSTIFFG(BK,T,GK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S);
if NML>0
QF=zeros(2*NCJT,1);
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFEFG
FF=zeros(2*NCJT,1);
FF=MFEFG(T,QF,FF);
%Call of STOREPF
P=STOREPF(JB,JE,NCJT,NDOF,NSC,FF,P);
IM=IM+1;
else IM=IM+1;
end
end
I=1;
while I<=NJL
I1=JP(I);
I2=(I1-1)*NCJT;
J=1;
80
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
end
d=S\P;
%R = Reactions vector
%V = Global displacement vector
%U = Local displacement vector
%F = Global force vector
%Q = Local force vector
%IM = Counters and flags
R=zeros(NR,1);
memendfortab=zeros(NM*2,5);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I);
I=MPRP(IM,4);
A=CP(I,1);
ZI=CP(I,2);
81
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
CX=(XE-XB)/BL;
CY=(YE-YB)/BL;
V=zeros(2*NCJT,1);
T=zeros(2*NCJT);
U=zeros(2*NCJT,1);
BK=zeros(2*NCJT);
Q=zeros(2*NCJT,1);
F=zeros(2*NCJT,1);
%Call of MDISPG
V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V);
%Call of MTRANS
T=MTRANS(CX,CY,T);
%Call of MDISPL
U=MDISPL(V,T,U);
%Call of MSTIFFL
BK=MSTIFFL(E,G,J,ZI,BL,BK);
QF=zeros(2*NCJT,1);
if NML>0
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFORCEL
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
82
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
end
%Call of MFORCEG
F=MFORCEG(T,Q);
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,F,R);
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP]';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
MEMLOAD_table=[MP PM]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
83
fprintf('\t%g \t\t\t\t\t%g \t\t\t\t\t%g \n',EM_table);
fprintf('\n\t\t\t Cross-Sectional Properties \n\n');
fprintf('Property No \tPolar Moment of Inertia (J) \tMoment of Inertia
(I) \n');
fprintf('\t%g \t\t\t\t\t%g \t\t\t\t\t%g \n',CP_table);
fprintf('\n\t\t\t\t\t\t Member Data \n\n');
fprintf('Member No \tBeginning Joint \tEnd Joint \tMaterial No
\tCross-Sectional Property No \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t\t\t%g
\n',MPRP_table);
fprintf('\n\t\t\t\t\t Joint Loads \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\tMoment \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \n',JPPJ_table);
fprintf('\n\t\t\t\t\t\t\t Member Loads \n\n');
fprintf('Member No \tLoad Type \tMagnitude (W, M, w or w1) \tMagnitud
(w2) \tDistance l1 \tDistance l2\n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t\t%g \t\t\t\t%g
\t\t\t\t%g\n',MEMLOAD_table);
fprintf('\n\t\t\t\t\t End of Input Data \n\n');
fprintf('\n\n\t\t\t\t\t Results of analysis \n');
fprintf('\n\t\t\t\t\t Joint Displacements \n\n');
fprintf('Joint No \t\tY Translation \t\t\tXX Rotation (Rad) \t\t\tZZ
Rotation (Rad) \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t\t\t%e \n',joidistab');
fprintf('\n\t\t Member End Forces in Local Coordinates\n\n');
fprintf('Member \t\tJoint \t\tShear Force \t\tXX Moment \t\tZZ Moment
\n');
fprintf('\t%g \t\t%g \t\t\t%g \t\t\t%g \t\t\t%g\n',memendfortab');
fprintf('\n\t\t\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\t\tMoment \n');
fprintf('\t%g \t\t\t%g \t\t\t%g \t\t\t\t%g \n',supreatab');
fprintf('\n\t\t\t\t End of Analysis \n\n');
%Figures
IM=1;
while IM<=NM
%Undeformed geometry
JB=MPRP(IM,1);
JE=MPRP(IM,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
BL=((XE-XB)^2+(YE-YB)^2)^.5;
x=[XB;XE];
y=[YB;YE];
figure(1)
hold on
plot(x,y,'-o')
% %Shape functions
%
% %x1 = Discretization vector of the member (100 points default)
%
% x1=linspace(0,BL);
84
% y1=zeros(length(x1),1);
%
% N1=1-x1/BL; %Axial 1
% N2=1-3*(x1/BL).^2+2*(x1/BL).^3; %Shear 1
% N3=x1.*(1-x1/BL).^2; %Bending 1
% N4=x1/BL; %Axial
% N5=3*(x1/BL).^2-2*(x1/BL).^3; %Shear 2
% N6=(x1.^2/BL).*(-1+x1/BL); %Bending 2
%
% %Deformed shape
%
% %ampfac = Amplification factor
% %dd = Joint displacements vector for each element
%
% ampfac=10;
% dd=[joidistab(JB,2) joidistab(JB,3) joidistab(JB,4)
joidistab(JE,2) joidistab(JE,3) joidistab(JE,4)]';
%
% x2=x1+N1*dd(1)*ampfac+N4*dd(4)*ampfac;
%
y2=y1'+N2*dd(2)*ampfac+N3*dd(3)*ampfac+N5*dd(5)*ampfac+N6*dd(6)*ampfac
;
%
% figure(2)
% subplot(NM,1,IM)
% plot(x1,y1,x2,y2,'r')
%
% %Axial diagrams
%
% figure(5)
% subplot(NM,1,IM)
%
% xaxi=linspace(0,BL);
% yaxi=ones(1,length(xaxi))*memendfortab(IM*2-1,3);
%
% area(xaxi,yaxi)
%
% %Shear diagrams
%
%
%
% %Moment diagrams
%
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Input Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Joint data
85
%NCJT = Number of coordinates per joint
NCJT=6;
%COORD=[X Y Z]
COORD=[0 0 0;
-240 0 0;
0 -240 0;
0 0 -240];
[NJ x]=size(COORD);
%Support data
%MSUP=[NS TX TY TZ RX RY RZ]
MSUP=[2 1 1 1 1 1 1;
3 1 1 1 1 1 1;
4 1 1 1 1 1 1];
[NS x]=size(MSUP);
%EM=[E G]
EM=[29000 11500];
[NMP x]=size(EM);
%CP=[A IZ IY J]
CP=[32.9 716 236 15.1];
[NCP x]=size(CP);
%Member data
86
3 1 1 1 90;
4 1 1 1 30];
[NM x]=size(MPRP);
%Load data
%JP=[NJ]
JP=[1];
%PJ[PX PY PZ MX MY MZ]
PJ=[0 0 0 -1800 0 1800];
[NJL X]=size(PJ);
%MP=[NM LOADTYPE]
MP=[1 3];
[NML x]=size(PM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Analysis Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
NR=nnz(MSUP(:,2:NCJT+1));
NDOF=NCJT*NJ-NR;
NSC=zeros(NCJT*NJ,1);
I=1;
J=0;
K=NDOF;
while I<=NJ
ICOUNT=0;
I1=1;
87
while I1<=NS
if MSUP(I1,1)==I
ICOUNT=1;
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
if MSUP(I1,I2+1)==1
K=K+1;
NSC(I3,1)=K;
I2=I2+1;
else J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
end
I1=I1+1;
else I1=I1+1;
end
end
if ICOUNT==0
I2=1;
while I2<=NCJT
I3=(I-1)*NCJT+I2;
J=J+1;
NSC(I3,1)=J;
I2=I2+1;
end
I=I+1;
else I=I+1;
end
end
% JB = Initial node
% JE = Final node
% E = Young modulus
% G = Shear modulus
% A = Cross-section area
% IZ = Cross-section moment of inertia about Z
% IY = Cross-section moment of inertia about Y
% J = Tortional constant
% XB = X coordinate of initial node
% YB = Y coordinate of initial node
% ZB = Z coordinate of initial node
% XE = X coordinate of final node
% YE = Y coordinate of final node
% ZE = Z coordinate of final node
88
% BL = Length
% rxX, rxY, rxZ = Cosines about X axis
% PSI = Roll angle
% IM, I = Counters and flags
GK=zeros(2*NCJT);
S=zeros(NDOF);
BK=zeros(2*NCJT);
T=zeros(2*NCJT);
P=zeros(NDOF,1);
IM=1;
while IM<=NM
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I,1);
G=EM(I,2);
I=MPRP(IM,4);
A=CP(I,1);
IZ=CP(I,2);
IY=CP(I,3);
J=CP(I,4);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
rxX=(XE-XB)/BL;
rxY=(YE-YB)/BL;
89
rxZ=(ZE-ZB)/BL;
PSI=MPRP(IM,5);
%Call of MSTIFFL
BK=MSTIFFL(E,G,A,IZ,IY,J,BL,BK);
%Call of MTRANS
T=MTRANS(rxX,rxY,rxZ,PSI,XB,XE,ZB,ZE,T);
%Call of MSTIFFG
GK=MSTIFFG(BK,T,GK);
%Call of STORES
S=STORES(JB,JE,NCJT,NDOF,NSC,GK,S);
if NML>0
QF=zeros(2*NCJT,1);
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFEFG
FF=zeros(2*NCJT,1);
FF=MFEFG(T,QF,FF);
%Call of STOREPF
P=STOREPF(JB,JE,NCJT,NDOF,NSC,FF,P);
IM=IM+1;
else IM=IM+1;
end
end
I=1;
90
while I<=NJL
I1=JP(I);
I2=(I1-1)*NCJT;
J=1;
while J<=NCJT
I2=I2+1;
N=NSC(I2);
if N<=NDOF
P(N)=P(N)+PJ(I,J);
J=J+1;
else J=J+1;
end
end
I=I+1;
end
d=S\P;
%R = Reactions vector
%V = Global displacement vector
%U = Local displacement vector
%F = Global force vector
%Q = Local force vector
%IM = Counters and flags
R=zeros(NR,1);
memendfortab=zeros(NM*2,5);
IM=1;
while IM<=NM
91
JB=MPRP(IM,1);
JE=MPRP(IM,2);
I=MPRP(IM,3);
E=EM(I,1);
G=EM(I,2);
I=MPRP(IM,4);
A=CP(I,1);
IZ=CP(I,2);
IY=CP(I,3);
J=CP(I,4);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
rxX=(XE-XB)/BL;
rxY=(YE-YB)/BL;
rxZ=(ZE-ZB)/BL;
PSI=MPRP(IM,5);
V=zeros(2*NCJT,1);
T=zeros(2*NCJT);
U=zeros(2*NCJT,1);
BK=zeros(2*NCJT);
Q=zeros(2*NCJT,1);
F=zeros(2*NCJT,1);
%Call of MDISPG
V=MDISPG(JB,JE,NCJT,NDOF,NSC,d,V);
%Call of MTRANS
T=MTRANS(rxX,rxY,rxZ,PSI,XB,XE,ZB,ZE,T);
%Call of MDISPL
U=MDISPL(V,T,U);
%Call of MSTIFFL
BK=MSTIFFL(E,G,A,IZ,IY,J,BL,BK);
QF=zeros(2*NCJT,1);
if NML>0
IML=1;
while IML<=NML
if IM==MP(IML,1)
%Call of MFEFLL
92
QF=MFEFLL(IML,BL,MP,PM,QF);
IML=IML+1;
else IML=IML+1;
end
end
%Call of MFORCEL
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
[Q memendfortab]=MFORCEL(JB,JE,BK,U,QF,IM,memendfortab);
end
%Call of MFORCEG
F=MFORCEG(T,Q);
%Call of STORER
R=STORER(JB,JE,NCJT,NDOF,NSC,F,R);
IM=IM+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Results Module %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tables
COORD_table=[(1:NJ)' COORD]';
MSUP_table=MSUP';
EM_table=[(1:NMP)' EM]';
CP_table=[(1:NCP)' CP]';
MPRP_table=[(1:NM)' MPRP]';
JPPJ_table=[JP PJ]';
MEMLOAD_table=[MP PM]';
%Call of JOIDISTAB
joidistab=JOIDISTAB(NJ,NCJT,NSC,NDOF,d);
%Call of SUPREATAB
supreatab=SUPREATAB(MSUP,R,NS,NCJT);
93
fprintf('Number of material property sets (E G) : %g \n', NMP);
fprintf('Number of cross-sectional property sets (A IZ IY J) : %g \n',
NCP);
fprintf('\n*User must be conscious of the use of consistent units
\n\n');
fprintf('\n\t\t\t\t Joint Coordinates \n\n');
fprintf('Joint No \tX Coordinate \tY Coordinate \tZ Coordinate \n');
fprintf('\t%g \t\t\t%g \t\t\t%g \t\t\t%g \n',COORD_table);
fprintf('\n\t\t\t\t\t\t\t\t\t\t\t Supports \n\n');
fprintf('\t\t\t\t\t\t\t\t\t*1 represents a constraint\n\n');
fprintf('Joint No \tX Restraint \tY Restraint \tZ Restraint \tXX
Restraint \tYY Restraint \tZZ Restraint \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t\t\t%g \t\t\t\t%g
\t\t\t\t%g \n',MSUP_table);
fprintf('\n\t\t\t\t Material Properties \n\n');
fprintf('Material No \tModulus of Elasticity (E) \tShear Modulus (G)
\n');
fprintf('\t%g \t\t\t\t\t%g \t\t\t\t\t%g \n',EM_table);
fprintf('\n\t\t\t\t\t\t Cross-Sectional Properties \n\n');
fprintf('Property No \tArea (A) \tMoment of Inertia (IZ) \tMoment of
Inertia (IY) \tTorsional constant (J) \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t\t\t%g
\n',CP_table);
fprintf('\n\t\t\t\t\t\t\t\t\t Member Data \n\n');
fprintf('Member No \tBeginning Joint \tEnd Joint \tMaterial No
\tCross-Sectional Property No \tAngle of Roll PSI \n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t\t\t%g
\t\t\t\t\t\t\t%g \n',MPRP_table);
fprintf('\n\t\t\t\t\t\t\t\t\t\t Joint Loads \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\tZ Force \t\tXX Moment
\t\tYY Moment \t\tZZ Moment\n');
fprintf('\t%g \t\t\t\t%g \t\t\t\t%g \t\t\t%g \t\t\t%g \t\t\t%g
\t\t\t%g\n',JPPJ_table);
fprintf('\n\t\t\t\t\t\t\t\t\t\t Member Loads \n\n');
fprintf('Member No \tLoad Type \tMagnitude (W, M, w, w1 or MT)
\tMagnitud (w2) \tDistance l1 \tDistance l2 \tLoc. Coo. Dir. (x=0,
y=1, z=2) \n');
fprintf('\t%g \t\t\t%g \t\t\t\t%g \t\t\t\t\t\t%g \t\t\t\t%g \t\t\t\t%g
\t\t\t\t\t%g \n',MEMLOAD_table);
fprintf('\n\t\t\t\t\t\t\t\t\t End of Input Data \n\n');
fprintf('\n\n\t\t\t\t\t\t\t\t\t Results of analysis \n');
fprintf('\n\t\t\t\t\t\t\t\t\t Joint Displacements \n\n');
fprintf('Joint No \t\tX Translation \t\t\tY Translation \t\t\tZ
Translation \t\t\tX Rotation (Rad) \t\t\tY Rotation (Rad) \t\t\tZ
Rotation (Rad)\n');
fprintf('\t%g \t\t\t%g \t\t\t%g \t\t\t%g \t\t\t%e \t\t\t\t%e
\t\t\t\t%e \n',joidistab');
fprintf('\n\t\t\t\t\t\t\t Member End Forces in Local
Coordinates\n\n');
fprintf('Member \t\tJoint \t\tAxial Force \t\tShear Force Y \t\tShear
Force Z \t\tTorsion \t\tMoment Y \t\tMoment Z \n');
fprintf('\t%g \t\t%g \t\t\t%g \t\t\t%g \t\t\t%g \t\t\t%g \t\t%g \t\t%g
\n',memendfortab');
fprintf('\n\t\t\t\t\t\t\t\t\t\t Support reactions \n\n');
fprintf('Joint No \t\tX Force \t\tY Force \t\tZ Force \t\tX Moment
\t\tY Moment \t\tZ Moment \n');
fprintf('\t%g \t\t\t%g \t\t%g \t\t%g \t\t%g \t\t%g \t\t%g
\n',supreatab');
fprintf('\n\t\t\t\t\t\t\t\t\t\t End of Analysis \n\n');
%Figures
94
IM=1;
while IM<=NM
%Undeformed geometry
JB=MPRP(IM,1);
JE=MPRP(IM,2);
XB=COORD(JB,1);
XE=COORD(JE,1);
YB=COORD(JB,2);
YE=COORD(JE,2);
ZB=COORD(JB,3);
ZE=COORD(JE,3);
BL=((XE-XB)^2+(YE-YB)^2+(ZE-ZB)^2)^.5;
x1=[XB;XE];
y1=[YB;YE];
z1=[ZB;ZE];
figure(1)
hold on
plot3(x1,y1,z1,'-o')
IM=IM+1;
end
95