Mat Lab Beam Deflection
Mat Lab Beam Deflection
Shaun Salisbury
January 17, 2011
Contents
1 Introduction 2
2 Review : Solving a Set of Linear Equations 2
3 One Dimension Spring Elements 2
3.1 Multiple Connected Spring Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Spring Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 Summary of Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Beam Elements 6
4.1 Beam Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
A Matlab Code 10
1
1 Introduction
Beam deections could be calculated by direct integration but it becomes cumbersome for more complex
beams, especially if the problem is statically indeterminate. In this handout we will employ a method based
on techniques from nite element analysis but since we will limit ourselves to point loads and constant
cross-sections between joints, the solution will be exact.
2 Review : Solving a Set of Linear Equations
A set of linear equations can be written in matrix form as shown below where K is a square matrix of
constants, u is the vector of unknowns and F is a vector of constants.
Ku = F (1)
In order to solve the equations we require:
1. as many equations as unknowns
2. all the equations to be independent (none of the rows of K can be made from linear combinations of
some of the other rows, i.e. K is not a singular matrix)
Checking the rst condition is straightforward; K must be square and the number of rows in K, u, and
F must be the same. Checking the second condition is easy if you are using Matlab by computing the
determinant (det(K)) and ensuring it doesnt equal zero. Provided the above conditions are satised, we
can compute the unknowns with Matlab using:
u=K\F
You could instead use u=inv(K)*F, but Matlab advises against it since it is slower.
3 One Dimension Spring Elements
To gain an understanding of the process, we will consider simple one-dimensional springs. Each element has
two nodes, each which have one degree of freedomdisplacement, u.
f
1 f
2
k
e
u
2
u
1
Figure 1: Spring element.
We can write the forces acting on the element, f
1
and f
2
, in terms of the displacements, u
1
and u
2
and
the stiness k
e
.
k
e
(u
1
u
2
) = f
1
(2)
k
e
(u
2
+ u
1
) = f
2
(3)
2
or in the form ku = f:
k
e
k
e
k
e
k
e
u
1
u
2
f
1
f
2
(4)
The k matrix is called the stiness matrix and the f matrix is the force matrix. If you look at k, you
see that it is singular (the equations are not independent)! We actually have only one independent equation
which means at least one displacement must be specied. The physical reason for this is that one side
needs to be xed otherwise the whole spring will move (rigid body motion). The specied displacements are
called boundary conditions.
For the displacements which are not specied, a force must be specied at that joint otherwise you cannot
solve the equation. If one species a boundary condition at a joint then you cannot also specify the force at
that joint too. The force and displacement are related by the stiness and are not independent.
3.1 Multiple Connected Spring Elements
Now lets consider two springs connected together which have stinesses k
1
and k
2
. There are three external
forces F
1
, F
2
, and F
3
.
F
1
F
2
k
1
u
2
u
1
F
3
u
3
k
2
Figure 2: Multiple spring elements.
We can write the equations for each element:
k
1
k
1
k
1
k
1
u
1
u
2
f
1,1
f
2,1
(5)
k
2
k
2
k
2
k
2
u
2
u
3
f
2,2
f
3,2
(6)
Using the equations of equilibrium at each node we can relate the internal forces, f, to the external forces,
F.
f
1,1
= F
1
(7)
f
3,2
= F
3
(8)
f
2,1
+ f
2,2
= F
2
(9)
We can now combine both sets of matrices via the common node u
2
and the equilibrium equations:
k
1
k
1
0
k
1
k
1
+ k
2
k
2
0 k
2
k
2
u
1
u
2
u
3
F
1
F
2
F
3
(10)
3
The process of combining the stiness matrices is called assembly. We calculate the stiness matrix for
each element and then add it to the total stiness matrix starting at the rst node.
k
1
k
1
0
k
1
k
1
0
0 0 0
0 0 0
0 k
2
k
2
0 k
2
k
2
k
1
k
1
0
k
1
k
1
+ k
2
k
2
0 k
2
k
2
(11)
If we had 3 spring elements (4 nodes) connected sequentially, the total stiness matrix would be:
k
1
k
1
0 0
k
1
k
1
+ k
2
k
2
0
0 k
2
k
2
+ k
3
k
3
0 0 k
3
k
3
(12)
Again the total stiness matrix is singular and so we need to specify at least one displacement and then
either a displacement or a force (external) must be specied for each of the other nodes. Loads are simply
put in the force vector at the row corresponding to the node:
F
1
F
2
F
3
(13)
Incorporating displacement boundary conditions requires a bit more consideration since we wish to use
matrices in Matlab to solve the equations. This is best illustrated in an example.
3.2 Spring Example
Consider the two spring arrangement with k
1
= 10 N/mm and k
2
= 20 N/mm. The displacement of the
rst node is 3 mm. The external force on node 2 is 50 N and on node 3 is 100 N.
Our total stiness matrix is:
10 10 0
10 30 20
0 20 20
(14)
The total equation with the loads incorporated is:
10 10 0
10 30 20
0 20 20
u
1
u
2
u
3
F
1
50
100
(15)
To incorporate the boundary condition, we would eliminate the top equation and rewrite the other two
equations as:
10 30 20
0 20 20
3
u
2
u
3
50
100
(16)
but we can move u
1
to the right side of the equation since it is known:
10 30 20
0 20 20
u
2
u
3
50 (10)3
100 0(3)
(17)
Deleting rows is annoying in programs like Matlab so more often the row with the known displacement
is left in but simplied to:
1 0
0 30 20
0 20 20
u
1
u
2
u
3
3
50 (10)3
100 0(3)
3
80
100
(18)
Solving in Matlab gives:
4
u
1
= 3, u
2
= 18, u
3
= 23.
We can get the all the external forces by multiplying the total stiness matrix by the displacements:
1 0
10 30 20
0 20 20
3
18
23
F
1
F
2
F
3
150
50
100
(19)
We can also get the internal forces for each element now that we have all the displacements from the
stiness matrix for each individual element.
10 10
10 10
3
18
f
1,1
f
2,1
150
150
(20)
20 20
20 20
18
23
f
2,2
f
3,2
100
100
(21)
3.3 Summary of Method
1. Calculate the stiness matrix for each element.
2. Assemble the element stiness matrix in the total stiness matrix.
3. Put known external loads in appropriate location of load vector.
4. Incorporate boundary conditions (known deections) in stiness matrix and load vector.
5. Solve for unknown displacements.
6. If desired, calculate the external and internal forces from the displacements.
5
4 Beam Elements
The same procedure is used for beam elements, but beams have two types of loadsshear force and moment,
and two degrees of freedom at each jointdisplacement and slope.
y
1
y
2
1
2
M
1
R
1
M
2
R
2
x
Figure 3: Beam element.
Assuming that the modulus of elasticity, E, and second moment of area, I, are constant over the beam
element of length L, the equations for the slope, , and the displacement, y, for the beam element come from
direct integration:
(x) =
1
+
1
EI
M
1
x +
1
2
R
1
x
2
(22)
y(x) = y
1
+
1
x +
1
EI
1
2
M
1
x
2
+
1
6
R
1
x
3
(23)
We can again write the forces and moments in terms of the degrees of freedom which gives the matrix
equation for the element.
EI
L
3
12 6L 12 6L
6 4L
2
6L 2L
2
12 6L 12 6L
6L 2L
2
6L 4L
2
y
1
1
y
2
R
1
M
1
R
2
M
2
(24)
This equation is in the exact same form Ku = F as before (the EI/L
3
term is only factored out for
clarity). Analysis of the stiness matrix shows that now two degrees of freedom must be specied and
one of them must be a displacement (again to prevent rigid body motion). The solution steps are the
same as for spring elements as the following example will illustrate.
6
4.1 Beam Example
The beam shown below has two parts with dierent moments of inertia but with the same modulus. The
loading and boundary conditions are shown.
I=20mm
4
I=60mm
4
E=6000 MPa F=6 N
M=5 N.mm
60 mm 60 mm
40 mm
Figure 4: Beam example
We need to break the beam into 3 elements (4 nodes) because the force is not at the junction of the two
beam sections.
F=6 N
M=5 N.mm
1 2 3 4
L=40mm L=20mm L=60mm
I=20mm
4
I=20mm
4
I=60mm
4
Nodes #:
E=6000 MPa
Figure 5: Beam example nodes.
The individual stiness matrices are:
20 600 20 600
600 24000 600 12000
20 600 20 600
600 12000 600 24000
(25)
7
The assembled equations are:
y
1
1
y
2
2
y
3
3
y
4
0
0
6
0
0
0
0
50
(26)
Applying the boundary conditions (y
1
= 0,
1
= 0, y
4
= 0):
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 202.5 1350 180 1800 0 0
0 0 1350 36000 1800 12000 0 0
0 0 180 1800 200 1200 0 600
0 0 1800 12000 1200 48000 0 12000
0 0 0 0 0 0 1 0
0 0 0 0 600 12000 0 24000
y
1
1
y
2
2
y
3
3
y
4
0
0
6
0
0
0
0
50
(27)
Solving the equations gives:
y
1
1
y
2
2
y
3
3
y
4
0
0
0.3064
0.005404
0.30985
0.0042045
0
0.0035606
(28)
Keep in mind that the absolute maximum deection and slope may occur between nodes. But since
we know the exact equations (22, 23) we can get any point between the nodes. The Matlab program in
the appendix does just this and prints the maximum slope and deection and the shear, moment, slope and
deection graphs. The maximum absolute slope is 0.0103 and the maximum absolute deection is 0.3319.
The beam graphs are shown in gure 6.
8
0 20 40 60 80 100 120
-2
0
2
4
6
S
h
e
a
r
0 20 40 60 80 100 120
-200
-100
0
100
M
o
m
e
n
t
0 20 40 60 80 100 120
-0.02
-0.01
0
0.01
S
l
o
p
e
0 20 40 60 80 100 120
-0.4
-0.2
0
0.2
0.4
D
e
f
l
e
c
t
i
o
n
Figure 6: Beam example graphs.
9
A Matlab Code
%*************************************************************************
%***
%*** Beam Shear, Moment, Slope, and Deflection
%*** S. Salisbury 2010
%***
%*************************************************************************
%This program uses finite element methods to calculate the shear,
%moment, slope and deflection distribution along a beam. Analysis is
%limited to beams with constant cross-sections between nodes and only
%concentrated forces and moments applied at the nodes. This permits
%fewer nodes to be used since the form of the equations are known.
%
%One must be consistent in units (i.e. pounds-inches-psi, N-mm-MPa).
%Slope is in radians and deflection is in the consistent units.
%*************************************************************************
%*************************************************************************
%***Enter Data...
%*************************************************************************
clc; clear; %clear the workspace and command window
%Modulus of Elasticity
E=6000;
%Properties for each beam element
BeamProp=[
%length, I
40, 20;
20, 20;
60, 60;
];
%Known node deflections
% need at least 1 if a slope is specified,
% otherwise need 2 if no slopes are specified
NodeDef=[
%node, deflection
1, 0;
4, 0;
];
%Known node slopes
% need at least 1 if only 1 deflection specified
NodeSlp=[
%node, slope
1, 0;
];
%Applied node forces
10
ForApp=[
%node, force
2, -6;
];
%Applied node moments
MomApp=[
%node, moment
4, -50;
];
%Number of results per beam element
Nres=10;
%*************************************************************************
% Start calculations...
%*************************************************************************
Nelem=length(BeamProp(:,1)); %number of beam elements
Nnode=Nelem+1; %number of joints
Ndof=Nnode*2; %number of degrees of freedom (1 deflection and
% 1 slope per node)
%Construct stiffness matrix
%*************************************************************************
K=zeros(Ndof);%initialize stiffness array
for i=1:Nelem %for each beam element...
L=BeamProp(i,1); %get the length
EI=E*BeamProp(i,2); %get the section properties
%stiffness of local element
Ksect=EI/L^3*[
12, 6*L, -12, 6*L;
6*L, 4*L^2, -6*L, 2*L^2;
-12, -6*L, 12, -6*L;
6*L, 2*L^2, -6*L, 4*L^2;
];
%assemble in global stiffness matrix
Loc=2*i-1; %location of element in global matrix
for j=0:3
for k=0:3
K(Loc+j,Loc+k)=K(Loc+j,Loc+k)+Ksect(j+1,k+1);
end
end
end
%Construct Load Vector
%*************************************************************************
F=zeros(Ndof,1); %initialize load vector
%Incorporate nodal forces
if isempty(ForApp)==0 %check that array not empty
for i=1:length(ForApp(:,1))
11
F(ForApp(i,1)*2-1)=ForApp(i,2); %put in applied force
end
end
%Incorporate nodal moments
if isempty(MomApp)==0 %check that array not empty
for i=1:length(MomApp(:,1))
F(MomApp(i,1)*2)=MomApp(i,2); %put in applied moment
end
end
%Incoporate Boundary Conditions
%*************************************************************************
%deflections
for i=1:length(NodeDef(:,1)) %for each constraint...
Loc=NodeDef(i,1)*2-1; %get the column the constraint refers to
def=NodeDef(i,2); %get the deflection at this node
for j=1:Ndof %for each row...
if j~=Loc %if the row doesnt correspond to the constraint
F(j)=F(j)-K(j,Loc)*def; %move the known to right side of eqn.
K(j,Loc)=0; %elminiate it from the left side
else %if row corresponds to the constraint...
F(j)=def; %set the value on right side to constraint
for k=1:Ndof %elminate this equation from left side of eqn.
if k==Loc
K(j,k)=1;
else
K(j,k)=0;
end
end
end
end
end
%slopes
if isempty(NodeSlp)==0
for i=1:length(NodeSlp(:,1)) %for each constraint...
Loc=NodeSlp(i,1)*2; %get the column the constraint refers to
def=NodeSlp(i,2); %get the deflection at this node
for j=1:Ndof %for each row...
if j~=Loc %if the row doesnt correspond to the constraint
F(j)=F(j)-K(j,Loc)*def; %move known to right side of eqn.
K(j,Loc)=0; %elminiate it from the left side
else %if row corresponds to the constraint...
F(j)=def; %set the value on right side to constraint
for k=1:Ndof %elminate this equation from left side of eqn.
if k==Loc
K(j,k)=1;
else
K(j,k)=0;
end
end
12
end
end
end
end
%Solve for deflection and slopes
%*************************************************************************
u=zeros(Ndof,1); %initialize dof vector
u=K\F; %solve
%Calculate shear(V) and moment(M) at the nodes
%*************************************************************************
% limitations on type of problem mean shear is constant along element
% and moment varies linearly
xVM=zeros(Ndof,1); %initialize distance along beam for V & M
V=zeros(Ndof,1); %initialize shear (2 per node)
M=zeros(Ndof,1); %initialize moment (2 per node)
for i=1:Nelem %for each beam element...
% get the element properties
L=BeamProp(i,1);
EI=E*BeamProp(i,2);
%stiffness of local element (as before)
Ksect=EI/L^3*[
12, 6*L, -12, 6*L;
6*L, 4*L^2, -6*L, 2*L^2;
-12, -6*L, 12, -6*L;
6*L, 2*L^2, -6*L, 4*L^2;
];
Loc=2*i; %location in the V & M matrices
%calculate shear and moment at left and right end of element
for k=0:3
V(Loc)=V(Loc)+Ksect(1,k+1)*u(Loc-1+k);
M(Loc)=M(Loc)-Ksect(2,k+1)*u(Loc-1+k);
V(Loc+1)=V(Loc+1)-Ksect(3,k+1)*u(Loc-1+k);
M(Loc+1)=M(Loc+1)+Ksect(4,k+1)*u(Loc-1+k);
end
%distance
xVM(Loc+1)=xVM(Loc)+L;
xVM(Loc+2)=xVM(Loc+1);
end
%Print out nodal results
%*************************************************************************
disp(**Nodal Results**)
%Column titles
S=sprintf(%4s,Node);
S=strcat(S,sprintf( %12s,Distance));
S=strcat(S,sprintf( %12s,Deflection));
S=strcat(S,sprintf( %12s,Slope));
13
% total force and moment at nodes
S=strcat(S,sprintf( %12s,Force));
S=strcat(S,sprintf( %12s,Moment));
% Shear.2 and Moment.2 are at left side of beam element
% Shear.1 and Moment.1 are at right side of beam element
S=strcat(S,sprintf( %12s,Shear.2));
S=strcat(S,sprintf( %12s,Shear.1));
S=strcat(S,sprintf( %12s,Moment.2));
S=strcat(S,sprintf( %12s\n,Moment.1));
disp(S)
%Column Data
for i=1:Nnode
S=sprintf(%4d,i);
S=strcat(S,sprintf( %12.3g,xVM(i*2-1)));
S=strcat(S,sprintf( %12.3g,u(i*2-1)));
S=strcat(S,sprintf( %12.3g,u(i*2)));
S=strcat(S,sprintf( %12.3g,V(i*2-1)+ V(i*2)));
S=strcat(S,sprintf( %12.3g,M(i*2-1)+ M(i*2)));
S=strcat(S,sprintf( %12.3g,V(i*2-1)));
S=strcat(S,sprintf( %12.3g,V(i*2)));
S=strcat(S,sprintf( %12.3g,M(i*2-1)));
S=strcat(S,sprintf( %12.3g\n,M(i*2)));
disp(S)
end
%Calculate slope(slp) and deflection(y) at increments along elements
%*************************************************************************
% limitations on type of problem allow use of formulae
% from direct integration rather than many sub-elements
xG=0; %global distance from left end of beam to left end of element
xR=zeros(Nelem*Nres,1); %initialize global distance vector for results
slp=zeros(Nelem*Nres,1); %initialize slope vector
y=zeros(Nelem*Nres,1); %initialize deflection vector
for i=1:Nelem %for each beam element...
% get the element properties
L=BeamProp(i,1);
EI=E*BeamProp(i,2);
%calculate the distance, slope and deflection
for j=1:Nres %for each point along element...
xL=L/(Nres-1)*(j-1); %local distance from element left side
xR((i-1)*Nres+j)=xG+xL; %global distance
slp((i-1)*Nres+j)=u(2*i)+(V(2*i)*xL^2/2+M(2*i)*xL)/EI;
y((i-1)*Nres+j)=u(2*i-1)+u(2*i)*xL+ ...
(V(2*i)*xL^3/6+M(2*i)*xL^2/2)/EI;
end
xG=xG+L;
end
14
disp(sprintf(Maximum absolute deflection: %12.4f,...
max(max(y),abs(min(y)))));
disp(sprintf(Maximum absolute slope: %12.4f,...
max(max(slp),abs(min(slp)))));
%Plot out the data
%*************************************************************************
subplot(4,1,1)
area(xVM,V)
ylabel(Shear)
subplot(4,1,2)
area(xVM,M)
ylabel(Moment)
subplot(4,1,3)
area(xR,slp)
ylabel(Slope)
subplot(4,1,4)
area(xR,y)
ylabel(Deflection)
15