# Finite elements/Finite element basis functions
## Finite Element Basis Functions

The Finite Element Method provides a general and systematic technique for constructing basis functions for Galerkin's approximation of boundary value problems.
The idea of finite elements is to choose $N_{i}$ piecewise over subregions of the domain called finite elements. Such functions can be very simple, for example, polynomials of low degree. We measure the size of each subregion with a parameter $h$. As $h$ decreases more elements are introduced and more basis functions are needed. The square integrability condition implies that jumps in the value of the function are not allowed at the nodes.
The simplest basis functions are piecewise linear functions and the corresponding elements are line segments in 1D, triangles and quadrilaterals in 2D, and tetrahedra, prisms and hexahedra in 3D.
These basis functions have to be chosen from the space ${\mathcal {H}}_{0}^{n}$. Let $\Omega _{n}$ be the space of piecewise linear functions. It can be shown that $\Omega _{n}\subset {\mathcal {H}}_{0}^{n}$.
Let
    $0=x_{0}<x_{1}<x_{2}<\dots <x_{n}<x_{N+1}=1$
be a partition of $[0,1]$ into subintervals $I_{j}=x_{j},x_{j+1}$ of length
    $\Delta x_{j}=x_{j+1}-x_{j},\qquad j=1,2,\dots ,N+1$
Let $h=\max(h_{j})$ be a measure of overall fineness of the grid. Let us choose as basis functions the set of triangular functions shown in Figure 1.
* Figure 1. Finite element basis functions.
In algebraic form, these basis functions are defined as
    ${\text{(25)}}\qquad {N_{j}(x)={\begin{cases}{\cfrac {x-x_{j-1}}{x_{j}-x_{j-1}}},&x_{j-1}\leq x\leq x_{j}\\{\cfrac {x_{j+1}-x}{x_{j+1}-x_{j}}},&x_{j}\leq x\leq x_{j+1}\\0&{\text{otherwise}}\end{cases}}}$
Note that the shape functions also satisfy the following,
    ${N_{i}(x_{j})=\delta _{ij}={\begin{cases}1,&{\text{at nodes }}i=j.\\0,&{\text{at nodes }}i\neq j.\end{cases}}}$
The first derivatives of the basis functions are
    ${\text{(26)}}\qquad {{\frac {dN_{j}(x)}{dx}}={\begin{cases}{\cfrac {1}{x_{j}-x_{j-1}}},&x_{j-1}\leq x\leq x_{j}\\-{\cfrac {1}{x_{j+1}-x_{j}}},&x_{j}\leq x\leq x_{j+1}\\0&{\text{otherwise}}\end{cases}}}$
So there are discontinuities in the first derivatives at $x=x_{j}$ as you can see in Figure 2.
* Figure 2. Derivatives of finite element basis functions.
The Galerkin trial solution is
    $u_{h}=N_{0}+\sum _{i=1}^{n}a_{i}N_{i}$
where $n$ is the number of nodes in an element. If we have two nodes per element as shown in Figure 2, then within each element we have
    ${u_{h}^{e}=a_{1}N_{1}^{e}+a_{2}N_{2}^{e}~.}$
The basis functions $N_{i}^{e}$ are the element (or local) basis functions and are to be distinguished from the global basis functions centered around nodes.
If you look at the element that joins node $x_{j}$ to node $x_{j+1}$ you will see that there are two functions $N_{j}$ and $N_{j+1}$ that describe this element. The local basis functions for the element are therefore
    $N_{1}^{e}={\frac {x_{j+1}-x}{x_{j+1}-x_{j}}}\qquad {\text{and}}\qquad N_{2}^{e}={\frac {x-x_{j}}{x_{j+1}-x_{j}}}~.$
Hence we can write
    $u_{h}^{e}=a_{1}\left({\frac {x_{j+1}-x}{x_{j+1}-x_{j}}}\right)+a_{2}\left({\frac {x-x_{j}}{x_{j+1}-x_{j}}}\right)$
If we force the solution $u_{h}^{e}$ to be equal to $u_{j}$ at $x=x_{j}$ and $u_{j+1}$ at $x=x_{j+1}$, we get $a_{1}=u_{j}$ and $a_{2}=u_{j+1}$.
Therefore, the solution is approximated by the piecewise linear function,
    ${u_{h}^{e}=u_{j}\left({\frac {x_{j+1}-x}{x_{j+1}-x_{j}}}\right)+u_{j+1}\left({\frac {x-x_{j}}{x_{j+1}-x_{j}}}\right)}$
We could also write
    $u_{h}^{e}=(1-t)~u_{j}+t~u_{j+1}\qquad {\text{where}}~t=\left({\frac {x-x_{j}}{x_{j+1}-x_{j}}}\right)~.$
This a parametric representation of a line and shows very clearly that $u_{h}^{e}$ is a linear approximation. Figure 3 shows a schematic of a FE solution using linear shape functions.
* Figure 3. Schematic of a finite element solution computed using linear shape functions.