Laplace's Equation
Using the iterative solver (such as the Gauss-Seidel method), we begin with Laplace's equation in two dimensions:
\[
\frac{\partial^2 U}{\partial x^2} + \frac{\partial^2 U}{\partial y^2} = 0.
\]
Discretization of Laplace's Equation
The 2D Laplace equation is discretized using a finite difference method. In the code, this is done on a uniform grid, where the second derivatives with respect to \(x\) and \(y\) are approximated using central differences. Let's break this down.
Second derivative with respect to \(x\):
\[
\frac{\partial^2 U}{\partial x^2} \approx \frac{U_{i+1,j} - 2U_{i,j} + U_{i-1,j}}{(\Delta x)^2}
\]
where \(U_{i,j}\) is the value of \(U\) at grid point \((i,j)\) and \(\Delta x = \frac{L_x}{n_x - 1}\).
Second derivative with respect to \(y\):
\[
\frac{\partial^2 U}{\partial y^2} \approx \frac{U_{i,j+1} - 2U_{i,j} + U_{i,j-1}}{(\Delta y)^2}
\]
where \(\Delta y = \frac{L_y}{n_y - 1}\).
Discretized Laplace Equation
The discrete form of the Laplace equation (by adding the two central differences) becomes:
\[\small
\frac{U_{i+1,j} - 2U_{i,j} + U_{i-1,j}}{(\Delta x)^2} + \frac{U_{i,j+1} - 2U_{i,j} + U_{i,j-1}}{(\Delta y)^2} = 0.
\]
To simplify, we assume the grid is uniform, meaning \(\Delta x = \Delta y = h\). This gives:
\[\small
\frac{U_{i+1,j} - 2U_{i,j} + U_{i-1,j}}{h^2} + \frac{U_{i,j+1} - 2U_{i,j} + U_{i,j-1}}{h^2} = 0.
\]
Multiplying through by \(h^2\) and solving for \(U_{i,j}\):
\[
U_{i,j} = \frac{1}{4} \left( U_{i+1,j} + U_{i-1,j} + U_{i,j+1} + U_{i,j-1} \right).
\]
Recurrence Relation
The recurrence relation used in the iterative solver is derived from the above discretized equation. The updated value of \(U_{i,j}\) is obtained by averaging the neighboring points:
\[
U_{i,j}^{(new)} = \frac{1}{4} \left( U_{i+1,j}^{(old)} + U_{i-1,j}^{(old)} + U_{i,j+1}^{(old)} + U_{i,j-1}^{(old)} \right).
\]