# Derivation in the FEM method

Can any on help me understand how from the simple delta function on the right hand and performing the integration we can get values as in the left? Note that $h = x_i + 1 - x_i$

The diffusion and mass matrices are given by $$D_{ij} = \int_0^L \frac{d\phi_i}{dx}\frac{d\phi_j}{dx} dx = \left\{\begin{matrix} \frac{1}{h_1} &\text{if } i=j=1,\\ \frac{1}{h_{i-1}} + \frac{1}{h_{i}} &\text{if } i=j\neq 1 \text{ and } N_E +1,\\ \frac{1}{h_{N_E}} &\text{if } i=j=N_E+1,\\ -\frac{1}{h_{i}} &\text{if } j=i+1,\\ -\frac{1}{h_{i-1}} &\text{if } j=i-1,\\ 0 &\text{otherwise.} \end{matrix}\right.$$

and

$$M_{ij} = \int_0^L \phi_i \phi_j dx = \left\{\begin{matrix} \frac{1}{3}h_1 &\text{if } i=j=1,\\ \frac{1}{3}(h_{i-1} + h_i) &\text{if } i=j\neq 1 \text{ and } N_E +1,\\ \frac{1}{3}h_{N_E} &\text{if } i=j=N_E+1,\\ \frac{1}{6}h_{i} &\text{if } j=i+1,\\ \frac{1}{6}h_{i-1} &\text{if } j=i-1,\\ 0 &\text{otherwise.} \end{matrix}\right.$$

And the shape functions satisfy the condition $\phi_i(x_j) = \delta_{i,j}$ is the Kronecker delta.

References

1. Pozrikidis, Constantine. Introduction to finite and spectral element methods using MATLAB. CRC Press, 2005.

The basis functions seem to be piecewise linear with $\phi_i(x_j) = \delta_{ij}$, so $$\phi_i(x) = \begin{cases} \frac{1}{h_{i-1}}(x-x_{i-1}) \qquad &x\in[x_{i-1},x_i]\,,\\ \frac{-1}{h_{i}}(x-x_{i+1}) \qquad &x\in[x_{i},x_{i+1}]\,,\\ 0 & \text{otherwise}\,, \end{cases}$$ and as such $$\frac{\mathrm{d}\phi_i}{\mathrm{d}x}(x) = \begin{cases} \frac{1}{h_{i-1}} \qquad &x\in[x_{i-1},x_i]\,,\\ \frac{-1}{h_{i}} \qquad &x\in[x_{i},x_{i+1}]\,,\\ 0 & \text{otherwise}\,. \end{cases}$$
As an example to get you started, the first integral, we have to show $$\int_0^L \frac{\mathrm{d}\phi_i}{\mathrm{d}x} \frac{\mathrm{d}\phi_j}{\mathrm{d}x} \mathrm{d}x = \frac{1}{h_{i-1}} + \frac{1}{h_{i}} \quad \text{when } i=j\neq 1 \text{ and } N_E+1\,.$$ With $i=j$ and with the above definition $$\begin{split} \int_0^L \left(\frac{\mathrm{d}\phi_i}{\mathrm{d}x}\right)^2 \mathrm{d}x &= 0 + \int_{x_{i-1}}^{x_i} \frac1{h_{i-1}^2}\mathrm{d}x + \int_{x_{i}}^{x_{i+1}} \frac1{h_{i}^2}\mathrm{d}x + 0 \\ &= \left[\frac{x}{{h_{i-1}}^2}\right]_{x_{i-1}}^{x_i} + \left[\frac{x}{{h_{i}}^2}\right]_{x_{i}}^{x_{i+1}} \\ &= \frac{1}{h_{i-1}} + \frac{1}{h_{i-1}}\,. \end{split}$$