Beams are components which are subjected to bending. Analysis of beams is a fundamental part of solid mechanics (strength of materials). Therefore, a beam in transverse loading can be a reasonable starting point to apply the FEM.
Meshing is the process of dividing the geometry (domain) of the problem into a finite number of elements with simple shapes. The vertices of the elements are called nodes which are crucial in the FEM formulation.
Here, meshing is quite minimal as there are only two elements as shown above, and they are enough for this problem. The nodes are markes as red dots in the figure above.
Having the geometry reduced to a collection of elements by meshing, we now look for a relation to relate the variables of interest throughout the elements, to the values of those variable at the nodes, thus, roughly speaking, reducing the element to its nodes. Such a mathematical equation is referred to as the shape function for that element.
Beams do deflect and bend when loaded transversely, therefore the shape function here needs to relates deflections (i.e. transverse displacements and rotations) at points throughout the element to the nodal deflections and rotations:
The differential equation for a beam element is: $\frac{{d}^{4}y}{d{x}^{4}}=0$. (1)
This is due to the fact that for transversely loaded beams, if $w\left(x\right)$ is the transverse load per unit length and $y\left(x\right)$ the transverse deflection: $\frac{{d}^{4}y}{d{x}^{4}}=$ $w\left(x\right)$. And for an element, loads are only applied at the nodes, i.e. there is no load inside the element.
therefore a 3rd degree polynomial satisfies the equation: $y\left(x\right)={a}_{0}+{a}_{1}x+{a}_{2}{x}^{2}+{a}_{3}{x}^{3}$. (2)
If such a polynomial is used to derive the shape function, the solution will be exact.
The relation between rotation and deflection is : $\theta \left(x\right)=$ $\frac{dy}{dx}$. Thus, here: $\theta \left(x\right)={a}_{1}+2{a}_{2}x+3{a}_{3}{x}^{2}$. (3)
Now using the above equations for deflection and rotation, coefficients ${a}_{0}$ to ${a}_{3}$ can be written in terms of transverse deflections and rotations at the two nodes and the length of the element.
Let ${y}_{0}$ and ${\theta}_{0}$, be the transverse deflection and rotation at $x=0$, and ${y}_{1}$ and ${\theta}_{1}$ the transverse deflection and rotation at $x=L$, respectively. Then for $x=0$ and $x=L$ equations (2) and (3) will give:
${a}_{0}={y}_{0}$ , ${a}_{1}={\theta}_{0}$ , ${y}_{1}={a}_{0}+{a}_{1}L+{a}_{2}{L}^{2}+{a}_{3}{L}^{3}$ , and ${\theta}_{1}={a}_{1}+2{a}_{2}L+3{a}_{3}{L}^{3}$.
Trying to write ${a}_{0}$, ${a}_{1}$ ${a}_{2}$, ${a}_{3}$ in terms of ${y}_{0}$, ${y}_{1}$, ${\theta}_{0}$, ${\theta}_{1}$ will give:
${a}_{0}={y}_{0}$ , ${a}_{1}={\theta}_{0}$ , ${a}_{2}=\frac{3}{{L}^{2}}({y}_{1}{y}_{0})\frac{1}{L}(2{\theta}_{0}+{\theta}_{1})$ , ${a}_{3}=\frac{2}{{L}^{3}}({y}_{1}{y}_{0})\frac{1}{{L}^{2}}({\theta}_{0}+{\theta}_{1})$
Substituting theses into equation (2), and rearranging gives:
$y\left(x\right)=$ $\left[13{\left(\frac{x}{L}\right)}^{2}+2{\left(\frac{x}{L}\right)}^{3}\right]{y}_{0}+\left[x2\frac{{x}^{2}}{L}+\frac{{x}^{3}}{{L}^{2}}\right]{\theta}_{0}+\left[3{\left(\frac{x}{L}\right)}^{2}2{\left(\frac{x}{L}\right)}^{3}\right]{y}_{1}+\left[\left(\frac{{x}^{2}}{L}\right)+\frac{{x}^{3}}{{L}^{2}}\right]{\theta}_{1}$.
The last equation relates the quantities of deflection and rotation for every point throughout the element to the deflection and rotation at the nodes. Therefore it defines the shape function.
Let the coefficients of nodal displacements and rotations be named as:
${N}_{{y}_{0}}=\left[13{\left(\frac{x}{L}\right)}^{2}+2{\left(\frac{x}{L}\right)}^{3}\right]$ , ${N}_{{\theta}_{0}}=\left[x2\frac{{x}^{2}}{L}+\frac{{x}^{3}}{{L}^{2}}\right]$ , ${N}_{{y}_{1}}=\left[3{\left(\frac{x}{L}\right)}^{2}2{\left(\frac{x}{L}\right)}^{3}\right]$ , ${N}_{{\theta}_{1}}=\left[\left(\frac{{x}^{2}}{L}\right)+\frac{{x}^{3}}{{L}^{2}}\right]$
The shape function can be written in matrix form: $y\left(x\right)=$ $\left\{{N}_{{y}_{0}}{N}_{{\theta}_{0}}{N}_{{y}_{1}}{N}_{{\theta}_{1}}\right\}\left\{\begin{array}{l}{y}_{0}\\ {\theta}_{0}\\ {y}_{1}\\ {\theta}_{1}\end{array}\right\}$ .(4)
Now, we are looking for an equation to describe the loaddeflection behavior of individual elements. A linear equation like the spring formula $F=Kx$ , which in FEM will appear as a matrix equation relating loads applied at the nodes of an element to deflections and rotations of the nodes: $\left\{{\mathbf{F}}_{e}\right\}=\left[{\mathbf{K}}_{e}\right]\left\{{\mathbf{u}}_{e}\right\}$ , where $\left\{{\mathbf{F}}_{e}\right\}$ is the column matrix (vector) of the applied nodal loads, $\left\{{\mathbf{u}}_{e}\right\}$ the nodal deflections (and rotations) vector, and $\left[{\mathbf{K}}_{e}\right]$ is the element stiffness matrix.
For deriving the element stiffness matrix, total potential energy methods can be used, which is used here. Using the spring analogy, the approach is to reach at an equation similar to $U=\frac{1}{2}K{x}^{2}$, which here will be in the form of: ${U}_{e}=\frac{1}{2}{\left\{{\mathbf{u}}_{e}\right\}}^{T}\left[{\mathbf{K}}_{e}\right]\left\{{\mathbf{u}}_{e}\right\}$. Here, $\left\{{\mathbf{u}}_{e}\right\}$ is the nodal deflections vector and as said before, $\left[{\mathbf{K}}_{e}\right]$ is the element stiffness matrix.
For a beam in bending, ${U}_{b}$, the potential energy due to bending moment $M\left(x\right)$ along the beam is:
${U}_{b}={\int}_{0}^{L}\frac{{M}^{2}}{2EI}dx$. (5.a)
For beams, it is also known that: $M\left(x\right)=$ $EI\frac{{d}^{2}y}{d{x}^{2}}$ . (5.b)
For an element $EI$ is constant, therefore substituting equation (5.b) into equation (5.a) gives:
${U}_{b}=\frac{EI}{2}{\int}_{0}^{L}(\frac{{d}^{2}y}{d{x}^{2}}{)}^{2}dx$ . (5.c)
From equation (4), we can have:
$\frac{{d}^{2}}{d{x}^{2}}$ $\left({N}_{{y}_{0}}\right)=$ $\frac{6}{{L}^{2}}+\frac{12}{{L}^{3}}x$ , $\frac{{d}^{2}}{d{x}^{2}}$$\left({N}_{{\theta}_{0}}\right)=$$\frac{4}{L}+\frac{6}{{L}^{2}}x$ , $\frac{{d}^{2}}{d{x}^{2}}$$\left({N}_{{y}_{1}}\right)=$$\frac{6}{{L}^{2}}\frac{12}{{L}^{3}}x$ , $\frac{{d}^{2}}{d{x}^{2}}$$\left({N}_{{\theta}_{1}}\right)=$$\frac{2}{L}+\frac{6}{{L}^{2}}x$ .
Let us say: $\left\{\frac{{d}^{2}{N}_{{y}_{0}}}{d{x}^{2}}\phantom{\rule{15px}{0ex}}\frac{{d}^{2}{N}_{{\theta}_{0}}}{d{x}^{2}}\phantom{\rule{15px}{0ex}}\frac{{d}^{2}{N}_{{y}_{1}}}{d{x}^{2}}\phantom{\rule{15px}{0ex}}\frac{{d}^{2}{N}_{{\theta}_{1}}}{d{x}^{2}}\right\}=\left\{{B}_{1}\phantom{\rule{10px}{0ex}}{B}_{2}\phantom{\rule{10px}{0ex}}{B}_{3}\phantom{\rule{10px}{0ex}}{B}_{4}\right\}=\left\{\mathbf{B}\right\}$ . (5.d)
If $\left\{{y}_{0}{\theta}_{0}{y}_{1}{\theta}_{1}\right\}={\left\{\mathbf{u}\right\}}^{T}$ (superscript $T$ is the transpose operator) , we will have: $\frac{{d}^{2}y}{d{x}^{2}}=\left\{\mathbf{B}\right\}\left\{\mathbf{u}\right\}$. (5.e)
For every $n\times 1$, i.e. column vector $\left\{v\right\}$: ${v}^{2}={\leftv\right}^{2}={\left\{v\right\}}^{T}\left\{v\right\}$ . Therefore substituting (5.e) in (5.c) and rearrangement using matrix algebra will give:
${U}_{b}=$ $\frac{EI}{2}{\int}_{0}^{L}{\left\{\mathbf{u}\right\}}^{T}{\left\{\mathbf{B}\right\}}^{T}\left\{\mathbf{B}\right\}\left\{\mathbf{u}\right\}dx$ . (5.f)
Equation (4) shows that $\left. {\mathbf{u}\right\}$ and therefore also ${\left\{\mathbf{u}\right\}}^{T}$ are independent of the variable of the integral in equation (5.f),
thus: ${U}_{b}=\frac{1}{2}{\left\{\mathbf{u}\right\}}^{T}\left[\left(EI\right){\int}_{0}^{L}{\left\{\mathbf{B}\right\}}^{T}\left\{\mathbf{B}\right\}dx\right]\left\{\mathbf{u}\right\}$ . (5.g)
If we say: $\left[{K}_{e}\right]=\left(EI\right){\int}_{0}^{L}{\left\{\mathbf{B}\right\}}^{T}\left\{\mathbf{B}\right\}dx$ , (5.h)
equation (5.g) can be written as: ${U}_{b}=\frac{1}{2}{\left\{\mathbf{u}\right\}}^{T}\left[{K}_{e}\right]\left\{\mathbf{u}\right\}$ . (5.i)
Equation (5.d) means that: ${\left\{\mathbf{B}\right\}}^{T}\left\{\mathbf{B}\right\}=$ $\left[\begin{array}{cccc}{B}_{1}^{2}& {B}_{1}{B}_{2}& {B}_{1}{B}_{3}& {B}_{1}{B}_{4}\\ {B}_{1}{B}_{2}& {B}_{2}^{2}& {B}_{2}{B}_{3}& {B}_{2}{B}_{4}\\ {B}_{1}{B}_{3}& {B}_{2}{B}_{3}& {B}_{3}^{2}& {B}_{3}{B}_{4}\\ {B}_{1}{B}_{4}& {B}_{2}{B}_{4}& {B}_{3}{B}_{4}& {B}_{4}^{2}\end{array}\right]$ . (5.j)
Equation (5.h) shows that integrating the elements of the righthand side of equation (5.j) will give the element stiffness matrix for a beam in pure bending:
For a beam element with Young's moulus of $E$, cross section moment of inertia of $I$ and length of $L$, the following matrix equation holds:
$\frac{EI}{{L}^{3}}\left[\begin{array}{cccc}12& 6L& 12& 6L\\ 6L& 4{L}^{2}& 6L& 2{L}^{2}\\ 12& 6L& 12& 6L\\ 6L& 2{L}^{2}& 6L& 4{L}^{2}\end{array}\right]$ (6) $\left\{\begin{array}{l}{y}_{0}\\ {\theta}_{0}\\ {y}_{1}\\ {\theta}_{1}\end{array}\right\}$ $=\left\{\begin{array}{l}{P}_{0}\\ {M}_{0}\\ {P}_{1}\\ {M}_{1}\end{array}\right\}$ , which can be written as: $\left[{K}_{e}\right]\left\{{u}_{e}\right\}=\left\{{F}_{e}\right\}$ .
In equation (6), ${y}_{0}$, ${\theta}_{0}$, ${P}_{0}$ and ${M}_{0}$ are the transverse deflection, rotation, transverse load and moment at $x=0$, and ${y}_{1}$, ${\theta}_{1}$, ${P}_{1}$ and ${M}_{1}$ are the transverse deflection, rotation, transverse load and moment at $x=L$ , respectively.
The Above equation, can therefore serve as the beam element stiffness matrix for a beam element of length $L$.
for a beam with a rectangular cross section, $I=\frac{b{h}^{3}}{12}$, (7)
where $b$ and $h$ are the (flange) width and depth of the beam, respectively.

 , then element stiffness matrix is:12  12  
12  12  
(8)

 , then element stiffness matrix is:12  12  
12  12  
(9)
The equation (10) shows how the stiffness matrices of the individual elements are combined to make the global stiffness matrix.
$\left[\begin{array}{cccccc}{K}_{11}^{1}& {K}_{12}^{1}& {K}_{13}^{1}& {K}_{14}^{1}& 0& 0\\ {K}_{21}^{1}& {K}_{22}^{1}& {K}_{23}^{1}& {K}_{24}^{1}& 0& 0\\ {K}_{31}^{1}& {K}_{32}^{1}& ({K}_{33}^{1}+{K}_{11}^{2})& ({K}_{34}^{1}+{K}_{12}^{2})& {K}_{13}^{2}& {K}_{14}^{2}\\ {K}_{41}^{1}& {K}_{42}^{1}& ({K}_{43}^{1}+{K}_{21}^{2})& ({K}_{44}^{1}+{K}_{22}^{2})& {K}_{23}^{2}& {K}_{24}^{2}\\ 0& 0& {K}_{31}^{2}& {K}_{32}^{2}& {K}_{33}^{2}& {K}_{34}^{2}\\ 0& 0& {K}_{41}^{2}& {K}_{42}^{2}& {K}_{43}^{2}& {K}_{44}^{2}\end{array}\right]\phantom{\rule{0ex}{0ex}}$ (10) $\left\{\begin{array}{l}{y}_{0}\\ {\theta}_{0}\\ {y}_{1}\\ {\theta}_{1}\\ {y}_{2}\\ {\theta}_{2}\end{array}\right\}$ $=\left\{\begin{array}{l}{P}_{0}\\ {M}_{0}\\ {P}_{1}\\ {M}_{1}\\ {P}_{2}\\ {M}_{2}\end{array}\right\}$ , or: $\left[{K}_{g}\right]\left\{{u}_{g}\right\}=\left\{{F}_{g}\right\}$
Equation (11) shows how applying BCs makes the problem to be simplified as corresponding rows and columns are deleted for each BC.
BCs: 
${y}_{0}=0$ 
${\theta}_{0}=0$ 
${y}_{1}=0$ 
${\theta}_{1}=0$ 
${y}_{2}=0$ 
${\theta}_{2}=0$ 
Loads: 
${P}_{0}=$ [N] 
${M}_{0}=$ 0 [Nm] 
${P}_{1}=$ [N] 
${M}_{1}=$ 0 [Nm] 
${P}_{2}=$ [N] 
${M}_{2}=$ 0 [Nm] 
(11)
0  0  
0  0  
0  0  
0  0 
${y}_{0}$ 
${\theta}_{0}$ 
${y}_{1}$ 
${\theta}_{1}$ 
${y}_{2}$ 
${\theta}_{2}$ 
${P}_{0}$ 
${M}_{0}$ 
${P}_{1}$ 
${M}_{1}$ 
${P}_{2}$ 
${M}_{2}$ 
The reduced global stiffness matrix (after application of the BCs) is shown below, as well as the final results. The results for displacements are in meters and rotations in radians.