You are on page 1of 5

clear all

clc
%----------------------------------------------------------------------------%
% Frame
%
% Problem description
%
% Problem description
%
Solve the given frame structure using Matlab Program and compare the
results with that of ansys
%A=0.04 m2
%F1=70 kN

I=5x10-4 m4
h=0.39 m
F2=75kN
F3=50kN
L=4m

% 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' %
Variable descriptions
%
%
node(i,j) Element connectivity matrix that describes globalnode number
%
of first and second node (j)of each frame element (i)
%
%---------------------------------------------clear
nel=7;
nnel=2;
ndof=3;
nnode=(nnel-1)*nel+1;
sdof=nnode*ndof;

%
%
%
%
%

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

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


% %----------------------------nodes(1,1)=1; nodes(1,2)=2;
nodes(2,1)=2; nodes(2,2)=3;
nodes(3,1)=2; nodes(3,2)=4;
nodes(4,1)=4; nodes(4,2)=5;
nodes(5,1)=5; nodes(5,2)=6;
nodes(6,1)=6; nodes(6,2)=7;
nodes(7,1)=6; nodes(7,2)=8;
x(1)=0; y(1)=0;
x(2)=6; y(2)=8;
x(3)=0; y(3)=8;
x(4)=10; y(4)=8;
x(5)=13; y(5)=8;
x(6)=18; y(6)=8;
x(7)=24; y(7)=8;
x(8)=24; y(8)=0;
el=2.1*10^11;
area=0.04;

%
%
%
%
%
%
%
%

x,
x,
x,
x,
x,
x,
x,
x,

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

% elastic modulus
% cross-sectional area

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

global
global
global
global
global
global
global
global

axis
axis
axis
axis
axis
axis
axis
axis

xi=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(4)=0;
bcdof(5)=23;
bcval(5)=0;
bcdof(6)=24;
bcval(6)=0;

% moment of inertia of cross-section


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

transverse deflection at node 1


whose described value is 0
axial displacement at node 1 is
whose described value is 0
slope at node 1 is constrained
whose described value is 0
transverse deflection at node 5
whose described value is 0
axial displacement at node 5 is
whose described value is 0
slope at node 5 is constrained
whose described value is 0

ff=zeros(sdof,1);
kk=zeros(sdof,sdof);
index=zeros(nel*ndof,1);
ff(11)=-70000;
ff(14)=-75000;
ff(17)=-50000;

is constrained
constrained

is constrained
constrained

% initialization of system force vector


% initialization of system matrix
% initialization of index vector

% load applied at node 2 in the x direction


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

for iel=1:nel
% loop for the total number of elements
node1=nodes(iel,1);
% starting node number for element 'iel'
node2=nodes(iel,2);
% ending node number for element 'iel'
index=globaldof(node1,node2,ndof); % extract system dofs associated with
element
x1=x(node1); y1=y(node1);
% x and y coordinate values of 'node1'
x2=x(node2); y2=y(node2);
% x and y coordinate values of 'node2'
leng=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
k=frameel(el,xi,leng,area,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
fsol=kk\ff;
% solve the matrix equation and print
% print both exact and fem solutions
num=1:1:sdof;
store=[num' fsol]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%function [k]=frameel(el,xi,leng,area,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,m]=feframe2(el,xi,leng,area,rho,beta,ipt)
%
% Variable Description:
%
k - element stiffness matrix (size of 6x6)
%
m - element mass matrix (size of 6x6)
%
el - elastic modulus
%
xi - second moment of inertia of cross-section
%
leng - element length
%
area - area of beam cross-section
%
rho - mass density (mass per unit volume)
%
beta - angle between the local and global axes
ipt = 1: consistent mass matrix
%
is positive if the local axis is in the ccw direction from
%
the global axis
%-------------------------------------------------------------------------% stiffness matrix at the local axis
a=el*area/leng;
c=el*xi/(leng^3);
kl=[a
0
0
12*c
0
6*leng*c
-a
0
0 -12*c
0
6*leng*c

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

-a
0
0
a
0
0

0
-12* c
-6*leng*c
0
12*c
-6*leng*c

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

% coordinate transformation matrix


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

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

0
0
1
0
0
0

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

0
0
0
sin(beta)
cos(beta)
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]=feaplybc(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
%
%
For example, there are constraints at d.o.f=2 and 10
%
and their constrained values are 0.0 and 2.5,
%
respectively. Then, bcdof(1)=2 and bcdof(2)=10; and
%
bcval(1)=1.0 and bcval(2)=2.5.
%----------------------------------------------------------n=length(bcdof);
sdof=size(kk);
for i=1:n
c=bcdof(i);
for j=1:sdof
kk(c,j)=0;
end

end

kk(c,c)=1;
ff(c)=bcval(i);

You might also like