# 1D Poisson Equation with Finite Difference - OrangeOwlSolutions/PDEs GitHub Wiki

### Poisson equation:

$\frac{d^2T}{dx^2}=-f(x) \;\;\;\; x\in[a,b]$

$T(a) = T_a$

$T(b) = T_b$

### Discretization points:

$a=x_1, x_2, x_3, \ldots, x_N=b$

### Discretization:

$T(x_n) = T_n$

$n=1\;\;\;\;T_1 = T_a$

$n=2\;\;\;\;\frac{-T_3+2T_2}{\Delta x^2} = f(x_2)+\frac{T_a}{\Delta x^2}$

$n=3\;\;\;\;\frac{-T_4+2T_3-T_2}{\Delta x^2} = f(x_3)$

$\ldots$

$n=N-1 \;\;\;\; \frac{-T_{N-2}+2T_{N-1}}{\Delta x^2}=f(x_{N-1})+\frac{T_b}{\Delta x^2}$

$n=N\;\;\;\; T_N=T_b$

The discretized Poisson equation amounts at the solution of the linear system

$\underline{\underline{A}}\; \underline{y} = \underline{b}$

with

$\underline{\underline{A}}=\begin{pmatrix} 2& -1& 0& 0& \ldots& 0& 0& 0\\ -1& 2& -1& 0& \ldots& 0& 0& 0\\ 0& -1& 2& -1& \ldots& 0& 0& 0\\ \ldots& & & & & & & \\ 0& 0& 0& 0& & -1& 2& -1\\ 0& 0& 0& 0& \ldots& 0& -1& 2 \end{pmatrix}$

$\underline{y} = \begin{pmatrix} T_2\\ T_3\\ T_4\\ \ldots\\ T_{N-2}\\ T_{N-1} \end{pmatrix}$

$\underline{b} = \begin{pmatrix} f(x_2)+\frac{T_a}{\Delta x^2}\\ f(x_3)\\ f(x_4)\\ \ldots\\ f(x_{N-2})\\ f(x_{N-1})+\frac{T_b}{\Delta x^2} \end{pmatrix}$

Although the system matrix is tridiagonal, in the Matlab code the solution of the linear system is obtained without exploiting this information.