For $\Omega = (0,1)^2 \subseteq \mathbb R^2, f \in C(\Omega)$ consider the boundary value problem:
$-\Delta u(x,y) + u(x,y) = f(x,y)~ \forall (x,y) \in \Omega \\u(0,y) = u(1,y)~ \forall y \in (0,1) \\ u(x,0) = u(x,1)~ \forall x \in (0,1)$
For discretization let be: $n \in \mathbb N,~ h= \frac{1}{n}, ~ x_i =(i-1) \cdot h, ~ y_j = (j-1) \cdot h, ~ i,j = 1, \ldots, n+1.$
I want to find the linear equation system for the discretized solution: $u_{i,j} = u(x_i,y_j), ~i,j= 1, \ldots, n$.
So I need to find $Au = b$, where $b$ is given by $f_{i,j} = f(x_i,y_j)$.
I found out that
$\begin{align} \Delta u_{i,j}=\frac{1}{h^2} [u_{i-1,j}+u_{i+1,j}-4u_{ij} +u_{i,j-1}+u_{i,j+1}] \end{align}$,
but now I'm struggeling how to put that in an equation system with regard to the boundary conditions. Can anybody help?
Thanks in advance!
First of all, you need to rearrange the unknowns, $u_{i,j}$. They are points on a square lattice. Conventionally, we go from the lower left corner, to the right, then go back to the left, but one unit upward, and repeat this process. This way, you will get $(n+1)^2$ unknowns, named as $u_i, i=1,...,(n+1)^2$.
When setting up the equations, you have to be careful about the correspondence between your $u_{i,j}$ and $u_i$.
For example, let $n=5$, then $u_{3,4}$ is corresponding to $u_{21}$. This gives one of the equations: $$- \frac{1}{h^2} [u_{2,4}+u_{4,4}-4 u_{3,4}+u_{3,3}+u_{3,5}]+u_{3,4}=f_{3,4}$$ which is equivalent to (by some counting) $$- \frac{1}{h^2} [u_{20}+u_{22}-4 u_{21}+u_{15}+u_{27}]+u_{21}=f_{21}$$ Do this for all $i,j$, you will get a $(n+1)\times(n+1)$ system, with, for example, diagonal elements $\frac{4}{h^2}+1$.
For the boundary conditions, $u(0,y)$ can be represented by $u_1, u_7, ...$. $u(1,y)$ can be represented by $u_6, u_12,...$ To incorporate that boundary condition, change equation $1,7,...$ to $u_1-u_6=0, u_7-u_12=0,...$. The other one can be done similarly.
I hope this helps.