Problem 3: Method of relaxation. This is a numerical technique to solve the Laplace equation in a boundary value problem. The idea is as follows, the second partial derivative may be approximated by
$\frac{\partial^2 V}{\partial x^2} = \frac{V(x - h) - 2V(x) + V(x + h)}{h^2} + O(h^2)$, (1)
and the Laplacian in two dimensions may be approximated as
$\nabla^2 V = \frac{V(x - h, y) + V(x, y - h) + V(x + h, y) + V(x, y + h) - 4V(x, y)}{h^2} + O(h^2)$. (2)
Solving for $V(x, y)$ assuming $\nabla^2 V = 0$, gives
$V(x, y) = \frac{1}{4} [V(x - h, y) + V(x, y - h) + V(x + h, y) + V(x, y + h)] + O(h^4)$. (3)
The relaxation method uses this result to update an iterative solution for $V$. For a given boundary value problem, define an initial guess, $V^{(0)}(x, y)$ on a regular grid with spacing $h$, where $V^{(0)}$ matches the values on the boundary, and is arbitrary (typically zero) everywhere else. Then update your solution iteratively until it converges (while keeping the boundary values fixed),
$V^{(n+1)}(x, y) = \frac{1}{4} [V^{(n)}(x - h, y) + V^{(n)}(x, y - h) + V^{(n)}(x + h, y) + V^{(n)}(x, y + h)]$. (4)
Use this technique to solve Laplace's equation in a rectangle of sides 2 in the $x$ direction and 1 in the $y$ direction, with $V(0, y) = V(2, y) = 1$ and with $V(x, 0) = V(x, 1) = -1$. Plot your solution as either a colour map or a 3-d plot, as you prefer. Also plot your solution at the mid-plane of the rectangle along both axes. Choose a grid spacing that is small enough to resolve structure in $V$, but not take up too much memory in your code.