# Finite elements/Solution of Poisson equation
## Construction of Approximate Solutions

If we know that the problem is well-posed but does not have a closed form solution, we can go ahead and try to get an approximate solution. The finite element method is one way of getting at approximate solutions (among many other numerical methods).
The finite element method starts off with the variational form (or the weak form) of the BVP. The method is a special case of a class of methods called Galerkin methods.

## Finite element solution for the Poisson equation

Recall the variational boundary value problem for the Poisson equation:
The space ${\mathcal {X}}$ is continuous and an infinite number of functions could be chosen from this space of functions. In the finite element method, we choose a trial function from the space of approximate solutions ${\mathcal {X}}_{h}$ where ${\mathcal {X}}_{h}\subset {\mathcal {X}}$. A defining feature of these approximate trial solutions is that they are associated with a mesh or discretization of the domain $\Omega$. These functions also have the feature that they are finite dimensional with each dimension being associated with a node on the mesh.
Assume that we are given ${\mathcal {X}}_{h}$. Let us choose a weighting function $v_{h}\in {\mathcal {X}}_{h}$ that satisfies $v_{h}=0$ on $\Gamma _{T}$. We can choose another function $T_{h}\in {\mathcal {X}}_{h}$ as our trial solution. Since the boundary condition on $\Gamma _{T}$ is $T=0$, both $v_{h}$ and $T_{h}$ can have the same form. In the next section, we will look at the general form of the heat equation where $T\neq 0$ on the boundary.
In finite element methods we choose trial solutions $T_{h}$ of the form
    $T_{h}(\mathbf {x} )=T_{1}N_{1}(\mathbf {x} )+T_{2}N_{2}(\mathbf {x} )+\dots +T_{n}N_{n}(\mathbf {x} )=\sum _{i=1}^{n}T_{i}N_{i}(\mathbf {x} )~.$
where $T_{1}$, $T_{2}$, $\dots$, $T_{n}$ are nodal temperatures which are constant on ${\bar {\Omega }}$. The functions $N_{1},N_{2},\dots ,N_{n}$ form a basis that spans the subspace ${\mathcal {X}}_{h}$ and are known as basis functions or shape functions. Note that $n$ is the total number of nodes minus the number of nodes on $\Gamma _{T}$ where $T$ is specified.
Since the functions $v_{h}$ come from the same space of functions, we can represent them as
    $v_{h}(\mathbf {x} )=b_{1}N_{1}(\mathbf {x} )+b_{2}N_{2}(\mathbf {x} )+\dots +b_{n}N_{n}(\mathbf {x} )=\sum _{i=1}^{n}b_{i}N_{i}(\mathbf {x} )~.$
where $b_{1}$, $b_{2}$, $\dots$, $b_{n}$ are arbitrary constant on ${\bar {\Omega }}$ with the restriction that $v_{h}=0$ on $\Gamma _{T}$.
If we plug in these finite dimensional forms of $v$ and $T$ into the variational BVP, we get an approximate form of the variational BVP which can be stated as:
After substituting the expressions for $v_{h}$ and $T_{h}$ in the variational BVP we get
    ${\begin{aligned}0&=\int _{\Omega }{\boldsymbol {\nabla }}T_{h}\bullet {\boldsymbol {\nabla }}v_{h}~dV-\int _{\Omega }f~v_{h}~dV\\&=\int _{\Omega }{\boldsymbol {\nabla }}(T_{1}N_{1}+\dots +T_{n}N_{n})\bullet {\boldsymbol {\nabla }}(b_{1}N_{1}+\dots +b_{n}N_{n})~dV-\int _{\Omega }f~(b_{1}N_{1}+\dots +b_{n}N_{n})~dV\\&=\int _{\Omega }(T_{1}{\boldsymbol {\nabla }}N_{1}+\dots +T_{n}{\boldsymbol {\nabla }}N_{n})\bullet (b_{1}{\boldsymbol {\nabla }}N_{1}+\dots +b_{n}{\boldsymbol {\nabla }}N_{n})~dV-\int _{\Omega }f~(b_{1}N_{1}+\dots +b_{n}N_{n})~dV\\&=\sum _{i,j=1}^{n}K_{ij}T_{i}b_{j}-\sum _{j=1}^{n}f_{j}b_{j}\\&=\sum _{j=1}^{n}b_{j}\left[\sum _{i=1}^{n}K_{ij}T_{i}-f_{j}\right]\\\end{aligned}}$
where,
    ${K_{ij}=\int _{\Omega }{\boldsymbol {\nabla }}N_{i}\bullet {\boldsymbol {\nabla }}N_{j}~dV~~~~{\text{and}}~~~f_{j}=\int _{\Omega }fN_{j}~dV~.}$
In matrix form, we have
    ${\text{(38)}}\qquad \mathbf {b} ^{T}\left[\mathbf {K} \mathbf {T} -\mathbf {f} \right]=\mathbf {0}$
where $\mathbf {b} ^{T}=[b_{1},b_{2},\dots ,b_{n}]$, $\mathbf {K}$ is a $n\times n$ symmetric matrix, $\mathbf {T} =[T_{1},T_{2},\dots ,T_{n}]$ is a $n\times 1$ vector, and $\mathbf {f}$ is a $n\times 1$ vector.
Since $\mathbf {b}$ can be arbitrary, equation (38) can be further simplified to the form
    ${\text{(39)}}\qquad {\mathbf {K} \mathbf {T} =\mathbf {f} }$
This system of equations has a solution since $\mathbf {K}$ is positive-definite and therefore has an inverse. Once the $T_{i}$s are known, the approximate solution can be found using
    $T_{h}(\mathbf {x} )=T_{1}N_{1}(\mathbf {x} )+T_{1}N_{2}(\mathbf {x} )+\dots +T_{n}N_{n}(\mathbf {x} )~.$
The functions $N_{1},\dots ,N_{n}$ have special forms in the finite element method that have the property that the quality of the approximation improves with an increase in the dimension $n$ of the basis.