Multigrid Method for Solving Ax = b

Implementation of the Multigrid Method (MG) for solving Ax = b, uses Gauss-Seidel or Jacobi for smoothing. Includes V, W, and F cycle
393 Downloads
Updated 5 Feb 2023

View License

Multigrid Method (MG) for solving Ax = b is best described in the wiki article:
  1. Pre smoothing is preformed on the A matrix, GS or Jacboi
  2. Residual error is computed and downsampled to a coarser grid
  3. Coarser grid is solved through recursion of multirgird function
  4. Prolongation of correction is interpolated from the coarse grid to the original matrix
  5. Post smoothing is preformed on the A matrix, GS or Jacobi
  6. Repeat until converged or max iterations
This can be one of the fastest methods to solve Ax = b, and can even be O(n). However, this particle code isn't the fastest. This is best for learning how the method works.
V,W,F cyle are different ways to go through the grids, V has fast iterations but slow converagnce, F has slower iterations but faster converance, and W has slowest iterations but fastest convergance. Refer to wiki for a in depth explanation.
I followed the explanation given by Gilbert Strang for how to build the code:
Function gives you options for number of pre and post smoothing iterations, type of cycle (V,W,F), smoother type (Gauss-Seidel,Jacobi), amount of grid levels, max iterations, and tolerance.
Jacoobi is faster than Gauss-Seidel due to MATLAB's coding language however Gauss-Seidel is prefered as it is more stable.
Test scripts are provided to play around with the function.
This is the fastest and simpliest MG method for MATLAB I have seen. If you have any way to improve it please let me know

Cite As

Benjamin Beaudry (2026). Multigrid Method for Solving Ax = b (https://uk.mathworks.com/matlabcentral/fileexchange/123145-multigrid-method-for-solving-ax-b), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Version Published Release Notes
1.1.2

fixed typo

1.1.1

added A_b.mat file, added authors name

1.1.0

fixed bug in F and W cycle

1.0.0