We solve -u''(x)=f(x) with u(0)=u(1)=0, using the exact solution sin(kπx) and forcing f(x)=(kπ)²sin(kπx). N is rounded to the nearest 2^k+1.
Top = solution u(x) (blue solid = MG numerical solution / grey dashed = exact sin(kπx)) / Bottom = residual ‖r‖ on a log scale (blue = MG, red = GS only)
A finite-difference discretisation of the 1D Poisson equation gives, on each interior point i, the symmetric tridiagonal linear system $A\mathbf{u}=\mathbf{f}$ with diagonal 2 and off-diagonals -1.
Fine grid (spacing h) discretisation:
$$-\frac{u_{i-1}-2u_i+u_{i+1}}{h^2}=f_i$$Gauss-Seidel smoothing (removes high-frequency error):
$$u_i^{(\text{new})}=\tfrac{1}{2}\bigl(u_{i-1}^{(\text{new})}+u_{i+1}^{(\text{old})}+h^2 f_i\bigr)$$Full-weighting restriction (fine→coarse) and linear prolongation (coarse→fine):
$$r^{2h}_i=\tfrac{1}{4}r^{h}_{2i-1}+\tfrac{1}{2}r^{h}_{2i}+\tfrac{1}{4}r^{h}_{2i+1}$$The whole V-cycle (recursive):
$$u\leftarrow \text{Smooth}\circ \text{Prolong}\circ V_{2h}\circ \text{Restrict}\circ \text{Smooth}(u)$$Smooth error modes look high-frequency on the coarse grid, so the smoother kills them efficiently at every level. The result is a convergence factor that is independent of grid size and around 0.1 per cycle.