MATLAB Codes for Finite Element Analysis
MATLAB Codes for Finite
Element Analysis
Solids and Structures
A.J.M. Ferreira
Universidade do Porto
Portugal
123
Preface
This book intend to supply readers with some MATLAB codes for finite element
analysis of solids and structures.
After a short introduction to MATLAB, the book illustrates the finite element
implementation of some problems by simple scripts and functions.
The following problems are discussed:
• Discrete systems, such as springs and bars
• Beams and frames in bending in 2D and 3D
• Plane stress problems
• Plates in bending
• Free vibration of Timoshenko beams and Mindlin plates, including laminated
• Buckling of Timoshenko beams and Mindlin plates
composites
The book does not intends to give a deep insight into the finite element details,
just the basic equations so that the user can modify the codes. The book was
prepared for undergraduate science and engineering students, although it may be
useful for graduate students.
The MATLAB codes of this book are included in the disk. Readers are welcomed
to use them freely.
The author does not guarantee that the codes are error-free, although a major
effort was taken to verify all of them. Users should use MATLAB 7.0 or greater
when running these codes.
Any suggestions or corrections are welcomed by an email to ferreira@fe.up.pt.
Porto, Portugal,
Ant´onio Ferreira
2008
v
Contents
1
1
Short introduction to MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Operating with matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3
3
1.4
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.5 Matrix functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.6
Conditionals, if and switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Loops: for and while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.7
6
Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.8
7
1.9
Scalar functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
1.10 Vector functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.11 Matrix functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
1.12 Submatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.13 Logical indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.14 M-files, scripts and functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.15 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.15.1 2D plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.15.2 3D plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.16 Linear algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2 Discrete systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Springs and bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Equilibrium at nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Some basic steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
First problem and first MATLAB code . . . . . . . . . . . . . . . . . . . . . . . . 21
New code using MATLAB structures . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.1
2.2
2.3
2.4
2.5
2.6
3 Analysis of bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
A bar element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Numerical integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.1
3.2
vii
viii
Contents
3.3
3.4
3.5
An example of isoparametric bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Problem 2, using MATLAB struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4 Analysis of 2D trusses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2D trusses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Stiffness matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Stresses at the element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
First 2D truss problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
A second truss problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
An example of 2D truss with spring . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.1
4.2
4.3
4.4
4.5
4.6
4.7
5 Trusses in 3D space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Basic formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
A 3D truss problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
A second 3D truss example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.1
5.2
5.3
6 Bernoulli beams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Bernoulli beam problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Bernoulli beam with spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.1
6.2
6.3
7
2D frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.1
7.2
An example of 2D frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Another example of 2D frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.3
8 Analysis of 3D frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Stiffness matrix and vector of equivalent nodal forces . . . . . . . . . . . 103
First 3D frame example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Second 3D frame example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
8.1
8.2
8.3
8.4
9 Analysis of grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
A first grid example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
A second grid example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
9.1
9.2
9.3
10 Analysis of Timoshenko beams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.2 Formulation for static analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.3 Free vibrations of Timoshenko beams . . . . . . . . . . . . . . . . . . . . . . . . . 130
10.4 Buckling analysis of Timoshenko beams . . . . . . . . . . . . . . . . . . . . . . . 136