Nonlinear finite elements/Axial bar finite element solution

Axially loaded bar: The Finite Element Solution
The  finite element method is a type of Galerkin method that has the following advantages: As a result, computations can be done in a modular manner that is suitable for computer implementation.
 * 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.

Discretization
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.

Shape functions
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
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 3 and 4, $$N_2$$ is zero in element 4, $$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
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
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
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
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
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 & 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
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 & 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$$, $$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
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.

Matlab code
The finite element code (Matlab) used to compute this solution is given below.