Introduction to finite elements/Axial bar finite element solution

From Wikiversity
Jump to: navigation, search

Axially loaded bar: The Finite Element Solution[edit]

The finite element method is a type of Galerkin method that has the following advantages:

  1. The functions \varphi_i are found in a systematic manner.
  2. The functions \varphi_i are chosen such that they can be used for arbitrary domains.
  3. The functions \varphi_i are piecewise polynomials.
  4. The functions \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.

Discretization[edit]

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.

Shape functions[edit]

The functions \varphi_i have special characteristics in finite element methods and are generally written as N_i and are called basis functions, shape functions, or interpolation functions.

Therefore, we may write

\begin{align}
    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{align}

The finite element basis functions are chosen such that they have the following properties:

  1. The functions N_i are bounded and continuous.
  2. If there are n nodes, then there are n basis functions - one for each node. There are four basis functions for the mesh shown in Figure 6.
  3. Each function N_i is nonzero only on elements connected to node i.
  4. N_i is 1 at node i and zero at all other nodes.

Stiffness matrix[edit]

Let us compute the values of K_{ij} for the three element mesh. We have

\begin{align}
    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{align}

The components of \mathbf{K} are

\begin{align} 
    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{align}

The matrix \mathbf{K} is symmetric, so we don't need to explicitly compute the other terms.

From Figure 6, we see that N_1 is zero in elements 2 and 3, N_2 is zero in element 3, N_3 is zero in element 1, and N_4 is zero in elements 1 and 2. The same holds for dN_i/dx.

Therefore, the coefficients of the \mathbf{K} matrix become

\begin{align} 
    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{align}

We can simplify our calculation further by letting N^e_k be the shape functions over an element e. For example, the shape functions over element 2 are N^2_1 and N^2_2 where the local nodes 1 and 2 correspond to global nodes 2 and 3, respectively. Then we can write,

\begin{align} 
    K_{11} & = \int_{\Omega_1} \cfrac{dN^1_1}{dx} AE \cfrac{dN^1_1}{dx}~dx ~;~
    K_{12}  = \int_{\Omega_1} \cfrac{dN^1_2}{dx} AE \cfrac{dN^1_1}{dx}~dx ~;~
    K_{13}  = 0 ~;~
    K_{14}  = 0 \\
    K_{22} & = \int_{\Omega_1} \cfrac{dN^1_2}{dx} AE \cfrac{dN^1_2}{dx}~dx  +
               \int_{\Omega_2} \cfrac{dN^2_1}{dx} AE \cfrac{dN^2_1}{dx}~dx  ~;~
    K_{23}  = \int_{\Omega_2} \cfrac{dN^2_2}{dx} AE \cfrac{dN^2_1}{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^3_1}{dx} AE \cfrac{dN^3_1}{dx}~dx ~;~
    K_{34}  = \int_{\Omega_3} \cfrac{dN^3_2}{dx} AE \cfrac{dN^3_1}{dx}~dx \\
    K_{44} & = \int_{\Omega_3} \cfrac{dN^3_2}{dx} AE \cfrac{dN^3_2}{dx}~dx ~.
  \end{align}

Let K^e_{kl} be the part of the value of K_{ij} that is contributed by element e. The indices kl are local and the indices ij are global. Then,

\begin{align}
    K_{11} & = K^1_{11} ~;~
    K_{12}  =  K^1_{12} ~;~
    K_{13}  = 0 ~;~
    K_{14}  = 0 \\
    K_{22} & = K^1_{22} + K^2_{11} ~;~~
    K_{23}  = K^2_{12} ~;~~
    K_{24}  = 0 \\
    K_{33} & = K^2_{22} + K^3_{11} ~;~
    K_{34}  = K^3_{12} \\
    K_{44} & = K^3_{22} \\
  \end{align}

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 \mathbf{K}.

Stiffness matrix for two-noded elements[edit]

For our problem, if we consider an element e with two nodes, the local hat shape functions have the form


    N^e_1(\mathbf{x}) = \cfrac{\mathbf{x}_2 - \mathbf{x}}{h_e} ~;~~
    N^e_2(\mathbf{x}) = \cfrac{\mathbf{x} - \mathbf{x}_1}{h_e}

where h_e is the length of the element.

Then, the components of the element stiffness matrix are

\begin{align}
    K^e_{11} & = \int_{x_1}^{x_2} \cfrac{dN^e_1}{dx} AE \cfrac{dN^e_1}{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^e_{12} & = \int_{x_1}^{x_2} \cfrac{dN^e_2}{dx} AE \cfrac{dN^e_1}{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^e_{22} & = \int_{x_1}^{x_2} \cfrac{dN^e_2}{dx} AE \cfrac{dN^e_2}{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{align}

In matrix form,


    {
    \mathbf{K}^e = \cfrac{AE}{h_e} \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix}
    }

The components of the global stiffness matrix are

\begin{align}
    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{align}

In matrix form,


    {
    \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}
    }

Load vector[edit]

Similarly, for the load vector \mathbf{f}, we have

\begin{align}
    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{align}

The components of the load vector are

\begin{align}
    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{align}

Once again, since N_1 is zero in elements 2 and 3, N_2 is zero in element 3, N_3 is zero in element 1, and N_4 is zero in elements 1 and 2, we have

\begin{align}
    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{align}

Now, the boundary \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. Therefore, we have

\begin{align}
    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{align}

In terms of element shape functions, the above equations can be written as

\begin{align}
    f_1 & = \int_{\Omega_1} N^1_1\mathbf{q}~dx = f^1_1\\
    f_2 & = \int_{\Omega_1} N^1_2\mathbf{q}~dx + \int_{\Omega_2} N^2_1\mathbf{q}~dx 
          = f^1_2 + f^2_1\\
    f_3 & = \int_{\Omega_2} N^2_2\mathbf{q}~dx + \int_{\Omega_3} N^3_1\mathbf{q}~dx 
          = f^2_2 + f^3_1\\
    f_4 & = \int_{\Omega_3} N^3_2\mathbf{q}~dx + \left. N^3_2\boldsymbol{R}\right|_{x=L} 
          = f^3_2 + \boldsymbol{R}
  \end{align}

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 \mathbf{q} with a\mathbf{x}, the components of the element load vector \mathbf{f}^e are

\begin{align}
    f_1^e & = \int_{x_1}^{x_2} N^e_1 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^e_2 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{align}

In matrix form, the element load vector is written


    {
    \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

\begin{align}
    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{align}

Displacement trial function[edit]

Recall that we assumed that the displacement can be written as


    \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


    \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 is the total number of nodes in the domain. Also, recall that the value of N_i is 1 at node i and zero elsewhere. Therefore, we have

\begin{align}
    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{align}

Therefore, the trial function can be written as


    \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 are the nodal displacements.

Finite element system of equations[edit]

If all the elements are assumed to be of the same length h, the finite element system of equations (\mathbf{K}\mathbf{a} = \mathbf{f}) can then be written as


    \cfrac{AE}{h} 
    \begin{bmatrix} 
      1 & -1 & 0 & 0 \\
      -1 & 2 & -1 & 0 \\
      0 & -1 & 2 & -1 \\
      0 & 0 & -1 & 2 
    \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 \mathbf{u} = 0 at \mathbf{x} = 0. This is equivalent to setting u_1 = 0. The reduced system of equations is


    \cfrac{AE}{h} 
    \begin{bmatrix} 
      2 & -1 & 0 \\
      -1 & 2 & -1 \\
      0 & -1 & 2 
    \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, u_3, and u_4. Let us do that.

Assume that A, E, L, a, and R are all equal to 1. Then x_1 = 0, x_2 = 1/3, x_3 = 2/3, x_4 = 1, and h = 1/3. The system of equations becomes


    \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 is given by


    \mathbf{u}^e = u^e_1 N^e_1(\mathbf{x}) + u^e_2 N^e_2(\mathbf{x}) ~.

Therefore, the strain within an element is


    \boldsymbol{\varepsilon}^e = \frac{\partial \mathbf{u}^e}{\partial x} = u^e_1 \frac{\partial N^e_1}{\partial x} + 
          u^e_2 \frac{\partial N^e_2}{\partial x} ~.

In matrix notation,


    \boldsymbol{\varepsilon}^e = \mathbf{B}^e \mathbf{u}^e 
       = \left[ \frac{\partial N^e_1}{\partial x} ~~ \frac{\partial N^e_2}{\partial x}\right]
                        \begin{bmatrix} u^e_1 \\ u^e_2 \end{bmatrix}
       = \left[ -\cfrac{1}{h} ~~ \cfrac{1}{h} \right]
                        \begin{bmatrix} u^e_1 \\ u^e_2 \end{bmatrix}

The stress in the element is given by


    \boldsymbol{\sigma}^e = E\boldsymbol{\varepsilon}^e ~.

For our discretization, the element stresses are

\begin{align}
    \boldsymbol{\sigma}^1 & = 1.48 \\
    \boldsymbol{\sigma}^2 & = 1.37 \\
    \boldsymbol{\sigma}^3 & = 1.15 
  \end{align}

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.

Matlab code[edit]

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) + 1.0;
   
      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*E)*(-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;