The finite element method is a type of Galerkin method that has the
following advantages:
The functions
φ
i
{\displaystyle \varphi _{i}}
are found in a systematic manner.
The functions
φ
i
{\displaystyle \varphi _{i}}
are chosen such that they can be used for arbitrary domains.
The functions
φ
i
{\displaystyle \varphi _{i}}
are piecewise polynomials.
The functions
φ
i
{\displaystyle \varphi _{i}}
are non-zero only on a small part of the domain.
As a result, computations can be done in a modular manner that is suitable for computer implementation.
The first step in the finite element approach is to divide the domain into elements and nodes , i.e., to create the finite element mesh .
Let us consider a simple situation and divide the rod into 3 elements and 4 nodes as shown in Figure 6.
Figure 6. Finite element mesh and basis functions for the bar.
The functions
φ
i
{\displaystyle \varphi _{i}}
have special characteristics in finite element methods and are generally written as
N
i
{\displaystyle N_{i}}
and are called basis functions , shape functions , or interpolation functions .
Therefore, we may write
K
i
j
=
∫
0
L
d
N
j
d
x
A
E
d
N
i
d
x
d
x
f
j
=
∫
0
L
N
j
q
d
x
+
N
j
R
|
x
=
L
.
{\displaystyle {\begin{aligned}K_{ij}&=\int _{0}^{L}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx\\f_{j}&=\int _{0}^{L}N_{j}\mathbf {q} ~dx+\left.N_{j}{\boldsymbol {R}}\right|_{x=L}~.\end{aligned}}}
The finite element basis functions are chosen such that they have the
following properties:
The functions
N
i
{\displaystyle N_{i}}
are bounded and continuous.
If there are
n
{\displaystyle n}
nodes, then there are
n
{\displaystyle n}
basis functions - one for each node. There are four basis functions for the mesh shown in Figure 6.
Each function
N
i
{\displaystyle N_{i}}
is nonzero only on elements connected to node
i
{\displaystyle i}
.
N
i
{\displaystyle N_{i}}
is 1 at node
i
{\displaystyle i}
and zero at all other nodes.
Let us compute the values of
K
i
j
{\displaystyle K_{ij}}
for the three element mesh. We have
K
i
j
=
∫
0
L
d
N
j
d
x
A
E
d
N
i
d
x
d
x
=
∫
0
x
2
d
N
j
d
x
A
E
d
N
i
d
x
d
x
+
∫
x
2
x
3
d
N
j
d
x
A
E
d
N
i
d
x
d
x
+
∫
x
3
L
d
N
j
d
x
A
E
d
N
i
d
x
d
x
≡
∫
Ω
1
d
N
j
d
x
A
E
d
N
i
d
x
d
x
+
∫
Ω
2
d
N
j
d
x
A
E
d
N
i
d
x
d
x
+
∫
Ω
3
d
N
j
d
x
A
E
d
N
i
d
x
d
x
{\displaystyle {\begin{aligned}K_{ij}&=\int _{0}^{L}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx\\&=\int _{0}^{x_{2}}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx+\int _{x_{2}}^{x_{3}}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx+\int _{x_{3}}^{L}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx\\&\equiv \int _{\Omega _{1}}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{j}}{dx}}AE{\cfrac {dN_{i}}{dx}}~dx\end{aligned}}}
The components of
K
{\displaystyle \mathbf {K} }
are
K
11
=
∫
Ω
1
d
N
1
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
2
d
N
1
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
3
d
N
1
d
x
A
E
d
N
1
d
x
d
x
K
12
=
∫
Ω
1
d
N
2
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
2
d
N
2
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
3
d
N
2
d
x
A
E
d
N
1
d
x
d
x
K
13
=
∫
Ω
1
d
N
3
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
2
d
N
3
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
3
d
N
3
d
x
A
E
d
N
1
d
x
d
x
K
14
=
∫
Ω
1
d
N
4
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
2
d
N
4
d
x
A
E
d
N
1
d
x
d
x
+
∫
Ω
3
d
N
4
d
x
A
E
d
N
1
d
x
d
x
K
22
=
∫
Ω
1
d
N
2
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
2
d
N
2
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
3
d
N
2
d
x
A
E
d
N
2
d
x
d
x
K
23
=
∫
Ω
1
d
N
3
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
2
d
N
3
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
3
d
N
3
d
x
A
E
d
N
2
d
x
d
x
K
24
=
∫
Ω
1
d
N
4
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
2
d
N
4
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
3
d
N
4
d
x
A
E
d
N
2
d
x
d
x
K
33
=
∫
Ω
1
d
N
3
d
x
A
E
d
N
3
d
x
d
x
+
∫
Ω
2
d
N
3
d
x
A
E
d
N
3
d
x
d
x
+
∫
Ω
3
d
N
3
d
x
A
E
d
N
3
d
x
d
x
K
34
=
∫
Ω
1
d
N
4
d
x
A
E
d
N
3
d
x
d
x
+
∫
Ω
2
d
N
4
d
x
A
E
d
N
3
d
x
d
x
+
∫
Ω
3
d
N
4
d
x
A
E
d
N
3
d
x
d
x
K
44
=
∫
Ω
1
d
N
4
d
x
A
E
d
N
4
d
x
d
x
+
∫
Ω
2
d
N
4
d
x
A
E
d
N
4
d
x
d
x
+
∫
Ω
3
d
N
4
d
x
A
E
d
N
4
d
x
d
x
.
{\displaystyle {\begin{aligned}K_{11}&=\int _{\Omega _{1}}{\cfrac {dN_{1}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{1}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{1}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx\\K_{12}&=\int _{\Omega _{1}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx\\K_{13}&=\int _{\Omega _{1}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx\\K_{14}&=\int _{\Omega _{1}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx\\K_{22}&=\int _{\Omega _{1}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx\\K_{23}&=\int _{\Omega _{1}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx\\K_{24}&=\int _{\Omega _{1}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx\\K_{33}&=\int _{\Omega _{1}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx\\K_{34}&=\int _{\Omega _{1}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx\\K_{44}&=\int _{\Omega _{1}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{4}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{4}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{4}}{dx}}~dx~.\end{aligned}}}
The matrix
K
{\displaystyle \mathbf {K} }
is symmetric, so we don't need to explicitly compute the other terms.
From Figure 6, we see that
N
1
{\displaystyle N_{1}}
is zero in elements 3 and 4,
N
2
{\displaystyle N_{2}}
is zero in element 4,
N
3
{\displaystyle N_{3}}
is zero in element 1, and
N
4
{\displaystyle N_{4}}
is zero in elements 1 and 2. The same holds for
d
N
i
/
d
x
{\displaystyle dN_{i}/dx}
.
Therefore, the coefficients of the
K
{\displaystyle \mathbf {K} }
matrix become
K
11
=
∫
Ω
1
d
N
1
d
x
A
E
d
N
1
d
x
d
x
;
K
12
=
∫
Ω
1
d
N
2
d
x
A
E
d
N
1
d
x
d
x
;
K
13
=
0
;
K
14
=
0
K
22
=
∫
Ω
1
d
N
2
d
x
A
E
d
N
2
d
x
d
x
+
∫
Ω
2
d
N
2
d
x
A
E
d
N
2
d
x
d
x
;
K
23
=
∫
Ω
2
d
N
3
d
x
A
E
d
N
2
d
x
d
x
;
K
24
=
0
K
33
=
∫
Ω
2
d
N
3
d
x
A
E
d
N
3
d
x
d
x
+
∫
Ω
3
d
N
3
d
x
A
E
d
N
3
d
x
d
x
;
K
34
=
∫
Ω
3
d
N
4
d
x
A
E
d
N
3
d
x
d
x
K
44
=
∫
Ω
3
d
N
4
d
x
A
E
d
N
4
d
x
d
x
.
{\displaystyle {\begin{aligned}K_{11}&=\int _{\Omega _{1}}{\cfrac {dN_{1}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx~;~K_{12}=\int _{\Omega _{1}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{1}}{dx}}~dx~;~K_{13}=0~;~K_{14}=0\\K_{22}&=\int _{\Omega _{1}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{2}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx~;~K_{23}=\int _{\Omega _{2}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{2}}{dx}}~dx~;~K_{24}=0\\K_{33}&=\int _{\Omega _{2}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{3}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx~;~K_{34}=\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{3}}{dx}}~dx\\K_{44}&=\int _{\Omega _{3}}{\cfrac {dN_{4}}{dx}}AE{\cfrac {dN_{4}}{dx}}~dx~.\end{aligned}}}
We can simplify our calculation further by letting
N
k
e
{\displaystyle N_{k}^{e}}
be the shape functions over an element
e
{\displaystyle e}
. For example, the shape functions over element
2
{\displaystyle 2}
are
N
1
2
{\displaystyle N_{1}^{2}}
and
N
2
2
{\displaystyle N_{2}^{2}}
where the local nodes
1
{\displaystyle 1}
and
2
{\displaystyle 2}
correspond to global nodes
2
{\displaystyle 2}
and
3
{\displaystyle 3}
, respectively. Then we can write,
K
11
=
∫
Ω
1
d
N
1
1
d
x
A
E
d
N
1
1
d
x
d
x
;
K
12
=
∫
Ω
1
d
N
2
1
d
x
A
E
d
N
1
1
d
x
d
x
;
K
13
=
0
;
K
14
=
0
K
22
=
∫
Ω
1
d
N
2
1
d
x
A
E
d
N
2
1
d
x
d
x
+
∫
Ω
2
d
N
1
2
d
x
A
E
d
N
1
2
d
x
d
x
;
K
23
=
∫
Ω
2
d
N
2
2
d
x
A
E
d
N
1
2
d
x
d
x
;
K
24
=
0
K
33
=
∫
Ω
2
d
N
2
2
d
x
A
E
d
N
2
2
d
x
d
x
+
∫
Ω
3
d
N
1
3
d
x
A
E
d
N
1
3
d
x
d
x
;
K
34
=
∫
Ω
3
d
N
2
3
d
x
A
E
d
N
1
3
d
x
d
x
K
44
=
∫
Ω
3
d
N
2
3
d
x
A
E
d
N
2
3
d
x
d
x
.
{\displaystyle {\begin{aligned}K_{11}&=\int _{\Omega _{1}}{\cfrac {dN_{1}^{1}}{dx}}AE{\cfrac {dN_{1}^{1}}{dx}}~dx~;~K_{12}=\int _{\Omega _{1}}{\cfrac {dN_{2}^{1}}{dx}}AE{\cfrac {dN_{1}^{1}}{dx}}~dx~;~K_{13}=0~;~K_{14}=0\\K_{22}&=\int _{\Omega _{1}}{\cfrac {dN_{2}^{1}}{dx}}AE{\cfrac {dN_{2}^{1}}{dx}}~dx+\int _{\Omega _{2}}{\cfrac {dN_{1}^{2}}{dx}}AE{\cfrac {dN_{1}^{2}}{dx}}~dx~;~K_{23}=\int _{\Omega _{2}}{\cfrac {dN_{2}^{2}}{dx}}AE{\cfrac {dN_{1}^{2}}{dx}}~dx~;~K_{24}=0\\K_{33}&=\int _{\Omega _{2}}{\cfrac {dN_{2}^{2}}{dx}}AE{\cfrac {dN_{2}^{2}}{dx}}~dx+\int _{\Omega _{3}}{\cfrac {dN_{1}^{3}}{dx}}AE{\cfrac {dN_{1}^{3}}{dx}}~dx~;~K_{34}=\int _{\Omega _{3}}{\cfrac {dN_{2}^{3}}{dx}}AE{\cfrac {dN_{1}^{3}}{dx}}~dx\\K_{44}&=\int _{\Omega _{3}}{\cfrac {dN_{2}^{3}}{dx}}AE{\cfrac {dN_{2}^{3}}{dx}}~dx~.\end{aligned}}}
Let
K
k
l
e
{\displaystyle K_{kl}^{e}}
be the part of the value of
K
i
j
{\displaystyle K_{ij}}
that is contributed by element
e
{\displaystyle e}
. The indices
k
l
{\displaystyle kl}
are local and the indices
i
j
{\displaystyle ij}
are global. Then,
K
11
=
K
11
1
;
K
12
=
K
12
1
;
K
13
=
0
;
K
14
=
0
K
22
=
K
22
1
+
K
11
2
;
K
23
=
K
12
2
;
K
24
=
0
K
33
=
K
22
2
+
K
11
3
;
K
34
=
K
12
3
K
44
=
K
22
3
{\displaystyle {\begin{aligned}K_{11}&=K_{11}^{1}~;~K_{12}=K_{12}^{1}~;~K_{13}=0~;~K_{14}=0\\K_{22}&=K_{22}^{1}+K_{11}^{2}~;~~K_{23}=K_{12}^{2}~;~~K_{24}=0\\K_{33}&=K_{22}^{2}+K_{11}^{3}~;~K_{34}=K_{12}^{3}\\K_{44}&=K_{22}^{3}\\\end{aligned}}}
We can therefore see that if we compute the stiffness matrices over
each element and assemble them in an appropriate manner, we can get the
global stiffness matrix
K
{\displaystyle \mathbf {K} }
.
Stiffness matrix for two-noded elements
edit
For our problem, if we consider an element
e
{\displaystyle e}
with two nodes, the local hat shape functions have the form
N
1
e
(
x
)
=
x
2
−
x
h
e
;
N
2
e
(
x
)
=
x
−
x
1
h
e
{\displaystyle N_{1}^{e}(\mathbf {x} )={\cfrac {\mathbf {x} _{2}-\mathbf {x} }{h_{e}}}~;~~N_{2}^{e}(\mathbf {x} )={\cfrac {\mathbf {x} -\mathbf {x} _{1}}{h_{e}}}}
where
h
e
{\displaystyle h_{e}}
is the length of the element.
Then, the components of the element stiffness matrix are
K
11
e
=
∫
x
1
x
2
d
N
1
e
d
x
A
E
d
N
1
e
d
x
d
x
=
∫
x
1
x
2
(
−
1
h
e
)
A
E
(
−
1
h
e
)
d
x
=
A
E
h
e
K
12
e
=
∫
x
1
x
2
d
N
2
e
d
x
A
E
d
N
1
e
d
x
d
x
=
∫
x
1
x
2
(
1
h
e
)
A
E
(
−
1
h
e
)
d
x
=
−
A
E
h
e
K
22
e
=
∫
x
1
x
2
d
N
2
e
d
x
A
E
d
N
2
e
d
x
d
x
=
∫
x
1
x
2
(
1
h
e
)
A
E
(
1
h
e
)
d
x
=
A
E
h
e
{\displaystyle {\begin{aligned}K_{11}^{e}&=\int _{x_{1}}^{x_{2}}{\cfrac {dN_{1}^{e}}{dx}}AE{\cfrac {dN_{1}^{e}}{dx}}~dx=\int _{x_{1}}^{x_{2}}\left(-{\cfrac {1}{h_{e}}}\right)AE\left(-{\cfrac {1}{h_{e}}}\right)~dx={\cfrac {AE}{h_{e}}}\\K_{12}^{e}&=\int _{x_{1}}^{x_{2}}{\cfrac {dN_{2}^{e}}{dx}}AE{\cfrac {dN_{1}^{e}}{dx}}~dx=\int _{x_{1}}^{x_{2}}\left({\cfrac {1}{h_{e}}}\right)AE\left(-{\cfrac {1}{h_{e}}}\right)~dx=-{\cfrac {AE}{h_{e}}}\\K_{22}^{e}&=\int _{x_{1}}^{x_{2}}{\cfrac {dN_{2}^{e}}{dx}}AE{\cfrac {dN_{2}^{e}}{dx}}~dx=\int _{x_{1}}^{x_{2}}\left({\cfrac {1}{h_{e}}}\right)AE\left({\cfrac {1}{h_{e}}}\right)~dx={\cfrac {AE}{h_{e}}}\end{aligned}}}
In matrix form,
K
e
=
A
E
h
e
[
1
−
1
−
1
1
]
{\displaystyle {\mathbf {K} ^{e}={\cfrac {AE}{h_{e}}}{\begin{bmatrix}1&-1\\-1&1\end{bmatrix}}}}
The components of the global stiffness matrix are
K
11
=
A
E
h
1
;
K
12
=
−
A
E
h
1
;
K
13
=
0
;
K
14
=
0
K
22
=
A
E
h
1
+
A
E
h
2
;
K
23
=
−
A
E
h
2
;
K
24
=
0
K
33
=
A
E
h
2
+
A
E
h
3
;
K
34
=
−
A
E
h
3
K
44
=
A
E
h
3
{\displaystyle {\begin{aligned}K_{11}&={\cfrac {AE}{h_{1}}}~;~~K_{12}=-{\cfrac {AE}{h_{1}}}~;~~K_{13}=0~;~~K_{14}=0\\K_{22}&={\cfrac {AE}{h_{1}}}+{\cfrac {AE}{h_{2}}}~;~~K_{23}=-{\cfrac {AE}{h_{2}}}~;~~K_{24}=0\\K_{33}&={\cfrac {AE}{h_{2}}}+{\cfrac {AE}{h_{3}}}~;~~K_{34}=-{\cfrac {AE}{h_{3}}}\\K_{44}&={\cfrac {AE}{h_{3}}}\\\end{aligned}}}
In matrix form,
K
=
A
E
[
1
h
1
−
1
h
1
0
0
1
h
1
+
1
h
2
−
1
h
2
0
1
h
2
+
1
h
3
−
1
h
3
Symm.
1
h
3
]
{\displaystyle {\mathbf {K} =AE{\begin{bmatrix}{\cfrac {1}{h_{1}}}&-{\cfrac {1}{h_{1}}}&0&0\\&{\cfrac {1}{h_{1}}}+{\cfrac {1}{h_{2}}}&-{\cfrac {1}{h_{2}}}&0\\&&{\cfrac {1}{h_{2}}}+{\cfrac {1}{h_{3}}}&-{\cfrac {1}{h_{3}}}\\{\text{Symm.}}&&&{\cfrac {1}{h_{3}}}\\\end{bmatrix}}}}
Similarly, for the load vector
f
{\displaystyle \mathbf {f} }
, we have
f
j
=
∫
0
L
N
j
q
d
x
+
N
j
R
|
x
=
L
=
∫
Ω
1
N
j
q
d
x
+
∫
Ω
2
N
j
q
d
x
+
∫
Ω
3
N
j
q
d
x
+
N
j
R
|
x
=
L
{\displaystyle {\begin{aligned}f_{j}&=\int _{0}^{L}N_{j}\mathbf {q} ~dx+\left.N_{j}{\boldsymbol {R}}\right|_{x=L}\\&=\int _{\Omega _{1}}N_{j}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{j}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{j}\mathbf {q} ~dx+\left.N_{j}{\boldsymbol {R}}\right|_{x=L}\end{aligned}}}
The components of the load vector are
f
1
=
∫
Ω
1
N
1
q
d
x
+
∫
Ω
2
N
1
q
d
x
+
∫
Ω
3
N
1
q
d
x
+
N
1
R
|
x
=
L
f
2
=
∫
Ω
1
N
2
q
d
x
+
∫
Ω
2
N
2
q
d
x
+
∫
Ω
3
N
2
q
d
x
+
N
2
R
|
x
=
L
f
3
=
∫
Ω
1
N
3
q
d
x
+
∫
Ω
2
N
3
q
d
x
+
∫
Ω
3
N
3
q
d
x
+
N
3
R
|
x
=
L
f
4
=
∫
Ω
1
N
4
q
d
x
+
∫
Ω
2
N
4
q
d
x
+
∫
Ω
3
N
4
q
d
x
+
N
4
R
|
x
=
L
{\displaystyle {\begin{aligned}f_{1}&=\int _{\Omega _{1}}N_{1}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{1}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{1}\mathbf {q} ~dx+\left.N_{1}{\boldsymbol {R}}\right|_{x=L}\\f_{2}&=\int _{\Omega _{1}}N_{2}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{2}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{2}\mathbf {q} ~dx+\left.N_{2}{\boldsymbol {R}}\right|_{x=L}\\f_{3}&=\int _{\Omega _{1}}N_{3}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{3}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{3}\mathbf {q} ~dx+\left.N_{3}{\boldsymbol {R}}\right|_{x=L}\\f_{4}&=\int _{\Omega _{1}}N_{4}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{4}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{4}\mathbf {q} ~dx+\left.N_{4}{\boldsymbol {R}}\right|_{x=L}\end{aligned}}}
Once again, since
N
1
{\displaystyle N_{1}}
is zero in elements 2 and 3,
N
2
{\displaystyle N_{2}}
is zero in element 3,
N
3
{\displaystyle N_{3}}
is zero in element 1, and
N
4
{\displaystyle N_{4}}
is zero in elements 1 and 2, we have
f
1
=
∫
Ω
1
N
1
q
d
x
+
N
1
R
|
x
=
L
f
2
=
∫
Ω
1
N
2
q
d
x
+
∫
Ω
2
N
2
q
d
x
+
N
2
R
|
x
=
L
f
3
=
∫
Ω
2
N
3
q
d
x
+
∫
Ω
3
N
3
q
d
x
+
N
3
R
|
x
=
L
f
4
=
∫
Ω
3
N
4
q
d
x
+
N
4
R
|
x
=
L
{\displaystyle {\begin{aligned}f_{1}&=\int _{\Omega _{1}}N_{1}\mathbf {q} ~dx+\left.N_{1}{\boldsymbol {R}}\right|_{x=L}\\f_{2}&=\int _{\Omega _{1}}N_{2}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{2}\mathbf {q} ~dx+\left.N_{2}{\boldsymbol {R}}\right|_{x=L}\\f_{3}&=\int _{\Omega _{2}}N_{3}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{3}\mathbf {q} ~dx+\left.N_{3}{\boldsymbol {R}}\right|_{x=L}\\f_{4}&=\int _{\Omega _{3}}N_{4}\mathbf {q} ~dx+\left.N_{4}{\boldsymbol {R}}\right|_{x=L}\end{aligned}}}
Now, the boundary
x
=
L
{\displaystyle \mathbf {x} =L}
is at node 4 which is attached to element 3. The only non-zero shape function at this node is
N
4
{\displaystyle N_{4}}
. Therefore, we have
f
1
=
∫
Ω
1
N
1
q
d
x
f
2
=
∫
Ω
1
N
2
q
d
x
+
∫
Ω
2
N
2
q
d
x
f
3
=
∫
Ω
2
N
3
q
d
x
+
∫
Ω
3
N
3
q
d
x
f
4
=
∫
Ω
3
N
4
q
d
x
+
N
4
R
|
x
=
L
{\displaystyle {\begin{aligned}f_{1}&=\int _{\Omega _{1}}N_{1}\mathbf {q} ~dx\\f_{2}&=\int _{\Omega _{1}}N_{2}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{2}\mathbf {q} ~dx\\f_{3}&=\int _{\Omega _{2}}N_{3}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{3}\mathbf {q} ~dx\\f_{4}&=\int _{\Omega _{3}}N_{4}\mathbf {q} ~dx+\left.N_{4}{\boldsymbol {R}}\right|_{x=L}\end{aligned}}}
In terms of element shape functions, the above equations can be written
as
f
1
=
∫
Ω
1
N
1
1
q
d
x
=
f
1
1
f
2
=
∫
Ω
1
N
2
1
q
d
x
+
∫
Ω
2
N
1
2
q
d
x
=
f
2
1
+
f
1
2
f
3
=
∫
Ω
2
N
2
2
q
d
x
+
∫
Ω
3
N
1
3
q
d
x
=
f
2
2
+
f
1
3
f
4
=
∫
Ω
3
N
2
3
q
d
x
+
N
2
3
R
|
x
=
L
=
f
2
3
+
R
{\displaystyle {\begin{aligned}f_{1}&=\int _{\Omega _{1}}N_{1}^{1}\mathbf {q} ~dx=f_{1}^{1}\\f_{2}&=\int _{\Omega _{1}}N_{2}^{1}\mathbf {q} ~dx+\int _{\Omega _{2}}N_{1}^{2}\mathbf {q} ~dx=f_{2}^{1}+f_{1}^{2}\\f_{3}&=\int _{\Omega _{2}}N_{2}^{2}\mathbf {q} ~dx+\int _{\Omega _{3}}N_{1}^{3}\mathbf {q} ~dx=f_{2}^{2}+f_{1}^{3}\\f_{4}&=\int _{\Omega _{3}}N_{2}^{3}\mathbf {q} ~dx+\left.N_{2}^{3}{\boldsymbol {R}}\right|_{x=L}=f_{2}^{3}+{\boldsymbol {R}}\end{aligned}}}
The above shows that the global load vector can also be assembled from the
element load vectors if we use finite element shape functions.
Load vector for two-noded elements
edit
Using the linear shape functions discussed earlier and replacing
q
{\displaystyle \mathbf {q} }
with
a
x
{\displaystyle a\mathbf {x} }
, the components of the element load vector
f
e
{\displaystyle \mathbf {f} ^{e}}
are
f
1
e
=
∫
x
1
x
2
N
1
e
a
x
d
x
=
∫
x
1
x
2
(
x
2
−
x
h
e
)
a
x
d
x
=
a
h
e
(
x
2
(
x
2
2
−
x
1
2
)
2
−
x
2
3
−
x
1
3
3
)
f
2
e
=
∫
x
1
x
2
N
2
e
a
x
d
x
=
∫
x
1
x
2
(
x
−
x
1
h
e
)
a
x
d
x
=
−
a
h
e
(
x
1
(
x
2
2
−
x
1
2
)
2
−
x
2
3
−
x
1
3
3
)
{\displaystyle {\begin{aligned}f_{1}^{e}&=\int _{x_{1}}^{x_{2}}N_{1}^{e}a\mathbf {x} ~dx=\int _{x_{1}}^{x_{2}}\left({\cfrac {x_{2}-x}{h_{e}}}\right)a\mathbf {x} ~dx={\cfrac {a}{h_{e}}}\left({\cfrac {x_{2}(x_{2}^{2}-x_{1}^{2})}{2}}-{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}\right)\\f_{2}^{e}&=\int _{x_{1}}^{x_{2}}N_{2}^{e}a\mathbf {x} ~dx=\int _{x_{1}}^{x_{2}}\left({\cfrac {x-x_{1}}{h_{e}}}\right)a\mathbf {x} ~dx=-{\cfrac {a}{h_{e}}}\left({\cfrac {x_{1}(x_{2}^{2}-x_{1}^{2})}{2}}-{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}\right)\end{aligned}}}
In matrix form, the element load vector is written
f
e
=
a
h
e
[
x
2
(
x
2
2
−
x
1
2
)
2
−
x
2
3
−
x
1
3
3
x
2
3
−
x
1
3
3
−
x
1
(
x
2
2
−
x
1
2
)
2
]
{\displaystyle {\mathbf {f} ^{e}={\cfrac {a}{h_{e}}}{\begin{bmatrix}{\cfrac {x_{2}(x_{2}^{2}-x_{1}^{2})}{2}}-{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}\\{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}-{\cfrac {x_{1}(x_{2}^{2}-x_{1}^{2})}{2}}\end{bmatrix}}}}
Therefore, the components of the global load vector are
f
1
=
a
h
1
(
x
2
(
x
2
2
−
x
1
2
)
2
−
x
2
3
−
x
1
3
3
)
f
2
=
a
h
1
(
x
2
3
−
x
1
3
3
−
x
1
(
x
2
2
−
x
1
2
)
2
)
+
a
h
2
(
x
3
(
x
3
2
−
x
2
2
)
2
−
x
3
3
−
x
2
3
3
)
f
3
=
a
h
2
(
x
3
3
−
x
2
3
3
−
x
2
(
x
3
2
−
x
2
2
)
2
)
+
a
h
3
(
x
4
(
x
4
2
−
x
3
2
)
2
−
x
4
3
−
x
3
3
3
)
f
4
=
a
h
3
(
x
4
3
−
x
3
3
3
−
x
3
(
x
4
2
−
x
3
2
)
2
)
+
R
{\displaystyle {\begin{aligned}f_{1}&={\cfrac {a}{h_{1}}}\left({\cfrac {x_{2}(x_{2}^{2}-x_{1}^{2})}{2}}-{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}\right)\\f_{2}&={\cfrac {a}{h_{1}}}\left({\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}-{\cfrac {x_{1}(x_{2}^{2}-x_{1}^{2})}{2}}\right)+{\cfrac {a}{h_{2}}}\left({\cfrac {x_{3}(x_{3}^{2}-x_{2}^{2})}{2}}-{\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}\right)\\f_{3}&={\cfrac {a}{h_{2}}}\left({\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}-{\cfrac {x_{2}(x_{3}^{2}-x_{2}^{2})}{2}}\right)+{\cfrac {a}{h_{3}}}\left({\cfrac {x_{4}(x_{4}^{2}-x_{3}^{2})}{2}}-{\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}\right)\\f_{4}&={\cfrac {a}{h_{3}}}\left({\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}-{\cfrac {x_{3}(x_{4}^{2}-x_{3}^{2})}{2}}\right)+{\boldsymbol {R}}\end{aligned}}}
Displacement trial function
edit
Recall that we assumed that the displacement can be written as
u
h
(
x
)
=
a
1
φ
1
(
x
)
+
a
2
φ
2
(
x
)
+
⋯
+
a
n
φ
n
(
x
)
=
∑
i
=
1
n
a
i
φ
i
(
x
)
.
{\displaystyle \mathbf {u} _{h}(\mathbf {x} )=a_{1}\varphi _{1}(\mathbf {x} )+a_{2}\varphi _{2}(\mathbf {x} )+\dots +a_{n}\varphi _{n}(\mathbf {x} )=\sum _{i=1}^{n}a_{i}\varphi _{i}(\mathbf {x} )~.}
If we use finite element shape functions, we can write the above as
u
h
(
x
)
=
a
1
N
1
(
x
)
+
a
2
N
2
(
x
)
+
⋯
+
a
n
N
n
(
x
)
=
∑
i
=
1
n
a
i
N
i
(
x
)
{\displaystyle \mathbf {u} _{h}(\mathbf {x} )=a_{1}~N_{1}(\mathbf {x} )+a_{2}~N_{2}(\mathbf {x} )+\dots +a_{n}~N_{n}(\mathbf {x} )=\sum _{i=1}^{n}a_{i}~N_{i}(\mathbf {x} )}
where
n
{\displaystyle n}
is the total number of nodes in the domain. Also, recall that the value of
N
i
{\displaystyle N_{i}}
is 1 at node
i
{\displaystyle i}
and zero elsewhere. Therefore, we have
u
1
:=
u
h
(
x
1
)
=
a
1
N
1
(
x
1
)
+
a
2
N
2
(
x
1
)
+
⋯
+
a
n
N
n
(
x
1
)
=
a
1
u
2
:=
u
h
(
x
2
)
=
a
1
N
1
(
x
2
)
+
a
2
N
2
(
x
2
)
+
⋯
+
a
n
N
n
(
x
2
)
=
a
2
⋮
u
n
:=
u
h
(
x
n
)
=
a
1
N
1
(
x
n
)
+
a
2
N
2
(
x
n
)
+
⋯
+
a
n
N
n
(
x
n
)
=
a
n
{\displaystyle {\begin{aligned}u_{1}&:=\mathbf {u} _{h}(\mathbf {x} _{1})=a_{1}~N_{1}(\mathbf {x} _{1})+a_{2}~N_{2}(\mathbf {x} _{1})+\dots +a_{n}~N_{n}(\mathbf {x} _{1})=a_{1}\\u_{2}&:=\mathbf {u} _{h}(\mathbf {x} _{2})=a_{1}~N_{1}(\mathbf {x} _{2})+a_{2}~N_{2}(\mathbf {x} _{2})+\dots +a_{n}~N_{n}(\mathbf {x} _{2})=a_{2}\\\vdots \\u_{n}&:=\mathbf {u} _{h}(\mathbf {x} _{n})=a_{1}~N_{1}(\mathbf {x} _{n})+a_{2}~N_{2}(\mathbf {x} _{n})+\dots +a_{n}~N_{n}(\mathbf {x} _{n})=a_{n}\\\end{aligned}}}
Therefore, the trial function can be written as
u
h
(
x
)
=
u
1
N
1
(
x
)
+
u
2
N
2
(
x
)
+
⋯
+
u
n
N
n
(
x
)
=
∑
i
=
1
n
u
i
N
i
(
x
)
{\displaystyle \mathbf {u} _{h}(\mathbf {x} )=u_{1}~N_{1}(\mathbf {x} )+u_{2}~N_{2}(\mathbf {x} )+\dots +u_{n}~N_{n}(\mathbf {x} )=\sum _{i=1}^{n}u_{i}~N_{i}(\mathbf {x} )}
where
u
i
{\displaystyle u_{i}}
are the nodal displacements .
Finite element system of equations
edit
If all the elements are assumed to be of the same length
h
{\displaystyle h}
, the finite element system of equations (
K
a
=
f
{\displaystyle \mathbf {K} \mathbf {a} =\mathbf {f} }
) can then be written as
A
E
h
[
1
−
1
0
0
−
1
2
−
1
0
0
−
1
2
−
1
0
0
−
1
1
]
[
u
1
u
2
u
3
u
4
]
=
a
h
[
(
x
2
(
x
2
2
−
x
1
2
)
2
−
x
2
3
−
x
1
3
3
)
(
x
2
3
−
x
1
3
3
−
x
1
(
x
2
2
−
x
1
2
)
2
)
+
(
x
3
(
x
3
2
−
x
2
2
)
2
−
x
3
3
−
x
2
3
3
)
(
x
3
3
−
x
2
3
3
−
x
2
(
x
3
2
−
x
2
2
)
2
)
+
(
x
4
(
x
4
2
−
x
3
2
)
2
−
x
4
3
−
x
3
3
3
)
(
x
4
3
−
x
3
3
3
−
x
3
(
x
4
2
−
x
3
2
)
2
)
+
R
h
a
]
{\displaystyle {\cfrac {AE}{h}}{\begin{bmatrix}1&-1&0&0\\-1&2&-1&0\\0&-1&2&-1\\0&0&-1&1\end{bmatrix}}{\begin{bmatrix}u_{1}\\u_{2}\\u_{3}\\u_{4}\end{bmatrix}}={\cfrac {a}{h}}{\begin{bmatrix}\left({\cfrac {x_{2}(x_{2}^{2}-x_{1}^{2})}{2}}-{\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}\right)\\\left({\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}-{\cfrac {x_{1}(x_{2}^{2}-x_{1}^{2})}{2}}\right)+\left({\cfrac {x_{3}(x_{3}^{2}-x_{2}^{2})}{2}}-{\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}\right)\\\left({\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}-{\cfrac {x_{2}(x_{3}^{2}-x_{2}^{2})}{2}}\right)+\left({\cfrac {x_{4}(x_{4}^{2}-x_{3}^{2})}{2}}-{\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}\right)\\\left({\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}-{\cfrac {x_{3}(x_{4}^{2}-x_{3}^{2})}{2}}\right)+{\boldsymbol {R}}{\cfrac {h}{a}}\end{bmatrix}}}
Essential boundary conditions
edit
To solve this system of equations we have to apply the essential boundary condition
u
=
0
{\displaystyle \mathbf {u} =0}
at
x
=
0
{\displaystyle \mathbf {x} =0}
. This is equivalent to setting
u
1
=
0
{\displaystyle u_{1}=0}
. The reduced system of equations is
A
E
h
[
2
−
1
0
−
1
2
−
1
0
−
1
1
]
[
u
2
u
3
u
4
]
=
a
h
[
(
x
2
3
−
x
1
3
3
−
x
1
(
x
2
2
−
x
1
2
)
2
)
+
(
x
3
(
x
3
2
−
x
2
2
)
2
−
x
3
3
−
x
2
3
3
)
(
x
3
3
−
x
2
3
3
−
x
2
(
x
3
2
−
x
2
2
)
2
)
+
(
x
4
(
x
4
2
−
x
3
2
)
2
−
x
4
3
−
x
3
3
3
)
(
x
4
3
−
x
3
3
3
−
x
3
(
x
4
2
−
x
3
2
)
2
)
+
R
h
a
]
{\displaystyle {\cfrac {AE}{h}}{\begin{bmatrix}2&-1&0\\-1&2&-1\\0&-1&1\end{bmatrix}}{\begin{bmatrix}u_{2}\\u_{3}\\u_{4}\end{bmatrix}}={\cfrac {a}{h}}{\begin{bmatrix}\left({\cfrac {x_{2}^{3}-x_{1}^{3}}{3}}-{\cfrac {x_{1}(x_{2}^{2}-x_{1}^{2})}{2}}\right)+\left({\cfrac {x_{3}(x_{3}^{2}-x_{2}^{2})}{2}}-{\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}\right)\\\left({\cfrac {x_{3}^{3}-x_{2}^{3}}{3}}-{\cfrac {x_{2}(x_{3}^{2}-x_{2}^{2})}{2}}\right)+\left({\cfrac {x_{4}(x_{4}^{2}-x_{3}^{2})}{2}}-{\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}\right)\\\left({\cfrac {x_{4}^{3}-x_{3}^{3}}{3}}-{\cfrac {x_{3}(x_{4}^{2}-x_{3}^{2})}{2}}\right)+{\boldsymbol {R}}{\cfrac {h}{a}}\end{bmatrix}}}
This system of equations can be solved for
u
2
{\displaystyle u_{2}}
,
u
3
{\displaystyle u_{3}}
, and
u
4
{\displaystyle u_{4}}
. Let us do that.
Assume that
A
{\displaystyle A}
,
E
{\displaystyle E}
,
L
{\displaystyle L}
,
a
{\displaystyle a}
, and
R
{\displaystyle R}
are all equal to 1. Then
x
1
=
0
{\displaystyle x_{1}=0}
,
x
2
=
1
/
3
{\displaystyle x_{2}=1/3}
,
x
3
=
2
/
3
{\displaystyle x_{3}=2/3}
,
x
4
=
1
{\displaystyle x_{4}=1}
, and
h
=
1
/
3
{\displaystyle h=1/3}
. The system of equations becomes
[
2
−
1
0
−
1
2
−
1
0
−
1
1
]
[
u
2
u
3
u
4
]
=
[
0.037
0.074
0.383
]
⟹
[
u
1
u
2
u
3
u
4
]
=
[
0.0
0.494
0.951
1.333
]
{\displaystyle {\begin{bmatrix}2&-1&0\\-1&2&-1\\0&-1&1\end{bmatrix}}{\begin{bmatrix}u_{2}\\u_{3}\\u_{4}\end{bmatrix}}={\begin{bmatrix}0.037\\0.074\\0.383\end{bmatrix}}\qquad \implies \qquad {\begin{bmatrix}u_{1}\\u_{2}\\u_{3}\\u_{4}\end{bmatrix}}={\begin{bmatrix}0.0\\0.494\\0.951\\1.333\end{bmatrix}}}
Computing element strains and stresses
edit
From the above, it is clear that the displacement field within an element
e
{\displaystyle e}
is given by
u
e
=
u
1
e
N
1
e
(
x
)
+
u
2
e
N
2
e
(
x
)
.
{\displaystyle \mathbf {u} ^{e}=u_{1}^{e}N_{1}^{e}(\mathbf {x} )+u_{2}^{e}N_{2}^{e}(\mathbf {x} )~.}
Therefore, the strain within an element is
ε
e
=
∂
u
e
∂
x
=
u
1
e
∂
N
1
e
∂
x
+
u
2
e
∂
N
2
e
∂
x
.
{\displaystyle {\boldsymbol {\varepsilon }}^{e}={\frac {\partial \mathbf {u} ^{e}}{\partial x}}=u_{1}^{e}{\frac {\partial N_{1}^{e}}{\partial x}}+u_{2}^{e}{\frac {\partial N_{2}^{e}}{\partial x}}~.}
In matrix notation,
ε
e
=
B
e
u
e
=
[
∂
N
1
e
∂
x
∂
N
2
e
∂
x
]
[
u
1
e
u
2
e
]
=
[
−
1
h
1
h
]
[
u
1
e
u
2
e
]
{\displaystyle {\boldsymbol {\varepsilon }}^{e}=\mathbf {B} ^{e}\mathbf {u} ^{e}=\left[{\frac {\partial N_{1}^{e}}{\partial x}}~~{\frac {\partial N_{2}^{e}}{\partial x}}\right]{\begin{bmatrix}u_{1}^{e}\\u_{2}^{e}\end{bmatrix}}=\left[-{\cfrac {1}{h}}~~{\cfrac {1}{h}}\right]{\begin{bmatrix}u_{1}^{e}\\u_{2}^{e}\end{bmatrix}}}
The stress in the element is given by
σ
e
=
E
ε
e
.
{\displaystyle {\boldsymbol {\sigma }}^{e}=E{\boldsymbol {\varepsilon }}^{e}~.}
For our discretization, the element stresses are
σ
1
=
1.48
σ
2
=
1.37
σ
3
=
1.15
{\displaystyle {\begin{aligned}{\boldsymbol {\sigma }}^{1}&=1.48\\{\boldsymbol {\sigma }}^{2}&=1.37\\{\boldsymbol {\sigma }}^{3}&=1.15\end{aligned}}}
A plot of this solution is shown in Figure 7.
Figure 7(a). FEM vs exact solutions for displacements of an axially loaded bar.
Figure 7(b). FEM vs exact solutions for stresses in an axially loaded bar.
The finite element code (Matlab) used to compute this solution is given below.
function AxialBarFEM
A = 1.0;
L = 1.0;
E = 1.0;
a = 1.0;
R = 1.0;
e = 3;
h = L/e;
n = e+1;
for i=1:n
node(i) = (i-1)*h;
end
for i=1:e
elem(i,:) = [i i+1];
end
K = zeros(n);
f = zeros(n,1);
for i=1:e
node1 = elem(i,1);
node2 = elem(i,2);
Ke = elementStiffness(A, E, h);
fe = elementLoad(node(node1),node(node2), a, h);
K(node1:node2,node1:node2) = K(node1:node2,node1:node2) + Ke;
f(node1:node2) = f(node1:node2) + fe;
end
f(n) = f(n) + R;
Kred = K(2:n,2:n);
fred = f(2:n);
d = inv(Kred)*fred;
dsol = [0 d'];
fsol = K*dsol';
sum(fsol)
figure;
p0 = plotDisp(E, A, L, R, a);
p1 = plot(node, dsol, 'ro--', 'LineWidth', 3); hold on;
legend([p0 p1],'Exact','FEM');
for i=1:e
node1 = elem(i,1);
node2 = elem(i,2);
u1 = dsol(node1);
u2 = dsol(node2);
[eps(i), sig(i)] = elementStrainStress(u1, u2, E, h);
end
figure;
p0 = plotStress(E, A, L, R, a);
for i=1:e
node1 = node(elem(i,1));
node2 = node(elem(i,2));
p1 = plot([node1 node2], [sig(i) sig(i)], 'r-','LineWidth',3); hold on;
end
legend([p0 p1],'Exact','FEM');
function [p] = plotDisp(E, A, L, R, a)
dx = 0.01;
nseg = L/dx;
for i=1:nseg+1
x(i) = (i-1)*dx;
u(i) = (1/(6*A*E))*(-a*x(i)^3 + (6*R + 3*a*L^2)*x(i));
end
p = plot(x, u, 'LineWidth', 3); hold on;
xlabel('x', 'FontName', 'palatino', 'FontSize', 18);
ylabel('u(x)', 'FontName', 'palatino', 'FontSize', 18);
set(gca, 'LineWidth', 3, 'FontName', 'palatino', 'FontSize', 18);
function [p] = plotStress(E, A, L, R, a)
dx = 0.01;
nseg = L/dx;
for i=1:nseg+1
x(i) = (i-1)*dx;
sig(i) = (1/(2*A))*(-a*x(i)^2 + (2*R + a*L^2));
end
p = plot(x, sig, 'LineWidth', 3); hold on;
xlabel('x', 'FontName', 'palatino', 'FontSize', 18);
ylabel('\sigma(x)', 'FontName', 'palatino', 'FontSize', 18);
set(gca, 'LineWidth', 3, 'FontName', 'palatino', 'FontSize', 18);
function [Ke] = elementStiffness(A, E, h)
Ke = (A*E/h)*[[1 -1];[-1 1]];
function [fe] = elementLoad(node1, node2, a, h)
x1 = node1;
x2 = node2;
fe1 = a*x2/(2*h)*(x2^2-x1^2) - a/(3*h)*(x2^3-x1^3);
fe2 = -a*x1/(2*h)*(x2^2-x1^2) + a/(3*h)*(x2^3-x1^3);
fe = [fe1;fe2];
function [eps, sig] = elementStrainStress(u1, u2, E, h)
B = [-1/h 1/h];
u = [u1; u2];
eps = B*u
sig = E*eps;