You are on page 1of 5

%----------------------------------------------------------------------------%

% Name: - Usman Teshita AND Mohammed Abrasha:


% Assignment 2. Question No. 2
%
% Find the deflection of a frame stucture which is made of three beams
%
% of lengths of 25 m and two inclined 10m long. The beams have the same
% cross-sections area of 0.04 m^2 and second moment inertia of 5x10^-4 m^4. %
% The elastic modulus of 2.1x10^11 pa.
%
% The frame is subjected to a concenterated load of 75, 60 & 50 KN at the
% longest beam and the two inclined short members are fixed.
%
% Use 7 elements to find the deflection of the frame.
%
%
%
% Variable descriptions
%
% x and y = global x and y coordiates of each node
%
% k = element stiffness matrix
%
% kk = system stiffness matrix
%
% ff = system force vector
%
% index = a vector containing system dofs associated with each element
%
% bcdof = a vector containing dofs associated with boundary conditions
%
% bcval = a vector containing boundary condition values associated with
%
%
the dofs in 'bcdof'
%
%----------------------------------------------------------------------------%
nel=7;
nnel=2;
ndof=3;
nnode=(nnel-1)*nel+1;
sdof=nnode*ndof;
x(1)=0; y(1)=0;
x(2)=0; y(2)=8;
x(3)=6; y(3)=8;
x(4)=11; y(4)=8;
x(5)=14; y(5)=8;
x(6)=19; y(6)=8;
x(7)=25; y(7)=8;
x(8)=25; y(8)=0;
E=2.1*(10^11);
A=0.04;
I=5*(10^-4);
bcdof(1)=1;
bcval(1)=0;
bcdof(2)=2;
bcval(2)=0;
bcdof(3)=3;
bcval(3)=0;
bcdof(4)=22;
bcval(22)=0;
bcdof(5)=23;
bcval(23)=0;
bcdof(6)=24;
bcval(24)=0;

%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%

%
%
%
%
%
x,
x,
x,
x,
x,
x,
x,
x,

number of elements
number of nodes per element
number of dofs per node
total number of nodes in system
total system dofs
y
y
y
y
y
y
y
y

coord.
coord.
coord.
coord.
coord.
coord.
coord.
coord.

values
values
values
values
values
values
values
values

of
of
of
of
of
of
of
of

node
node
node
node
node
node
node
node

1
2
3
4
5
6
7
8

in
in
in
in
in
in
in
in

terms
terms
terms
terms
terms
terms
terms
terms

of
of
of
of
of
of
of
of

the
the
the
the
the
the
the
the

elastic modulus
cross-sectional area
moment of inertia of cross-section
axial didplacement at node 1 is constrained
whose described value is 0
transverse deflection at node 1 is constrained
whose described value is 0
slope at node 1 is constrained
whose described value is 0
axial didplacement at node 8 is constrained
whose described value is 0
transverse deflection at node 8 is constrained
whose described value is 0
slope at node 8 is constrained
whose described value is 0

ff=zeros(sdof,1);
% initialization of system force vector
kk=zeros(sdof,sdof);
% initialization of system matrix
index=zeros(nel*ndof,1); % initialization of index vector

global
global
global
global
global
global
global
global

axis
axis
axis
axis
axis
axis
axis
axis

ff(11)=-75000;
ff(14)=-60000;
ff(17)=-50000;

% load applied at node 4 in the negative y direction


% load applied at node 5 in the negative y direction
% load applied at node 6 in the negative y direction

%----------------------------% nodal connectivity


%----------------------------nodes(1,1)=1;
nodes(2,1)=2;
nodes(3,1)=3;
nodes(4,1)=4;
nodes(5,1)=5;
nodes(6,1)=6;
nodes(7,1)=6;
for iel=1:nel

nodes(1,2)=3;
nodes(2,2)=3;
nodes(3,2)=4;
nodes(4,2)=5;
nodes(5,2)=6;
nodes(6,2)=7;
nodes(7,2)=8;
% loop for the total number of elements

nd(1)=nodes(iel,1);
nd(2)=nodes(iel,2);

% starting node number for element 'iel'


% ending node number for element 'iel'

x1=x(nd(1)); y1=y(nd(1));
x2=x(nd(2)); y2=y(nd(2));

% x and y coordinate values of 'node1'


% x and y coordinate values of 'node2'

L=sqrt((x2-x1)^2+(y2-y1)^2); % length of element 'iel'


if (x2-x1)==0; % compute the angle between the local and global axes
if y2>y1;
beta=pi/2;
else
beta=-pi/2;
end
else
beta=atan((y2-y1)/(x2-x1));
end
index=FEELDOF(nd,nnel,ndof); % extract system dofs for the element
k=Frameel(E,I,L,A,beta);

% compute element stiffness matrix

kk=feasmbl1(kk,k,index);

% assemble each element matrix into system matrix

end
[kk,ff]=FEAPLYC2(kk,ff,bcdof,bcval); % apply the boundary conditions
disp=1000*(kk\ff);

% solve the matrix equation and print in mm

% print the solution of the displacement


num=1:1:sdof;
results=[num' disp];
1.0000
2.0000
3.0000
4.0000
5.0000
6.0000

0.0000
-0.0000;
0
-7.6028;
27.0856
-3.5988;

7.0000 -7.6028;
8.0000
5.4930
9.0000 -3.5988;
10.0000 -7.6561;
11.0000 -15.6010;
12.0000 -4.6186;
13.0000 -7.6961;
14.0000 -22.0244;
15.0000
0.5753
16.0000 -7.7627;
17.0000
-6.0806;
18.0000
3.4899
19.0000 -7.7627;
20.0000 14.8589
21.0000
3.4899
22.0000
0
23.0000
0
24.0000
0
function[index]=feeldof(nd,nnel;ndof)
%---------------------------------------------------------% Purpose:
%
Compute system dofs associated with each element
%
% Synopsis:
%
[index]=feeldof(nd,nnel,ndof)
%
% Variable Description:
%
index - system dof vector associated with element "iel"
%
iel - element number whose system dofs are to be determined
%
nnel - number of nodes per element
%
ndof - number of dofs per node
%----------------------------------------------------------edof=nnel*ndof;
k=0;
for i=1:nnel
start = (nd(i)-1)*ndof;
for j=1:ndof
k=k+1;
index(k)=start+j;
end
end
function [k]=frameel(E,I;L;A;beta)
%-------------------------------------------------------------% Purpose:
%
Stiffness and mass matrices for the 2-d frame element
%
nodal dof {u_1 v_1 theta_1 u_2 v_2 theta_2}
%
% Synopsis:
%
[k]=frameel(E,I,L,A,beta)
%
% Variable Description:
%
k - element stiffness matrix (size of 6x6)
%
E - elastic modulus
%
I - second moment of inertia of cross-section
%
L - element length
%
A - area of beam cross-section
%
beta - angle between the local and global axes

%
is positive if the local axis is in the ccw direction from
%
the global axis
%-------------------------------------------------------------------------% stiffness matrix at the local axis
a=E*A/L;
c=E*I/(L^3);
kl=[a 0
0 12*c
0 6*L*c
-a 0
0 -12*c
0 6*L*c

0
6*L*c
4*L^2*c
0
-6*L*c
2*L^2*c

-a
0
0
a
0
0

0
-12* c
-6*L*c
0
12*c
-6*L*c

0;...
6*L*c;...
2*L^2*c;...
0;...
-6*L*c;...
4*L^2*c];

% coordinate transformation matrix


r=[ cos(beta)
-sin(beta)
0
0
0
0

sin(beta)
cos(beta)
0
0
0
0

0 0
0
0 0
0
1 0
0
0 cos(beta) sin(beta)
0 -sin(beta) cos(beta)
0 0
0

0;...
0;...
0;...
0;...
0;...
1];

% stiffness matrix at the global axis


k=r'*kl*r;
function [kk]=feasmbl1(kk,k;index)
%---------------------------------------------------------% Purpose:
%
Assembly of element matrices into the system matrix
%
% Synopsis:
%
[kk]=feasmbl1(kk,k,index)
%
% Variable Description:
%
kk - system matrix
%
k - element matri
%
index - d.o.f. vector associated with an element
%----------------------------------------------------------edof = length(index);
for i=1:edof
ii=index(i);
for j=1:edof
jj=index(j);
kk(ii,jj)=kk(ii,jj)+k(i,j);
end
end

function [kk,ff]=feaplyc2(kk,ff;bcdof;bcval)
%---------------------------------------------------------% Purpose:
%
Apply constraints to matrix equation [kk]{x}={ff}
%

% Synopsis:
%
[kk,ff]=feaplyc2(kk,ff,bcdof,bcval)
%
% Variable Description:
%
kk - system matrix before applying constraints
%
ff - system vector before applying constraints
%
bcdof - a vector containging constrained d.o.f
%
bcval - a vector containing contained value
%
%----------------------------------------------------------n=length(bcdof);
sdof=size(kk);
for i=1:n
c=bcdof(i);
for j=1:sdof
kk(c,j)=0;
end
kk(c,c)=1;
ff(c)=bcval(i);
end

You might also like