This repository contains a MATLAB program to solve the Poisson equation on a square domain
We aim to solve the following Poisson problem:
with boundary conditions:
u(0, y) = u(1, y) = u(x, 0) = u(x, 1) = 0, \quad 0 \leq x, y \leq 1.
The discretized Laplacian operator is approximated as:
where
- Support for three iterative methods: Jacobi, Gauss-Seidel, and SOR.
-
Automatic optimization of the relaxation parameter
$$\omega$$ for SOR. - Vectorized operations for efficient computation.
- Sparse matrix representations to handle large grids with minimal memory usage.
- Visual output for solution and convergence behavior.
To solve the Poisson equation with a specific method, run the provided script.m
or use the following code structure:
N = 29; % Grid size
omega_guess = []; % Initial guess for omega (used in SOR)
tol = 1e-13; % Convergence tolerance
% Define source term f
f = zeros(N, N);
h = 1 / (N + 1);
f(round(3/4 * N), round(1/3 * N)) = 1 / h^2; % Example point source
% Solve using the desired method
[u, omega, rho, A] = solve_poisson(f, 'Method', 'SOR', 'Omega', omega_guess, 'Tolerance', tol);
-
solve_poisson.m
: Main function to solve the Poisson equation. -
build_matrix.m
: Constructs the sparse coefficient matrix$$A$$ for the Poisson equation. -
jacobi.m
: Implements the Jacobi iterative method. -
gauss_seidel.m
: Implements the Gauss-Seidel iterative method. -
sor.m
: Implements the Successive Over-Relaxation method. -
spectral_radius.m
: Calculates the spectral radius of a matrix to check convergence. -
TEST.m
: Script to run tests and validate the implementation and convergence of the iterative methods.
The script generates visual outputs, including:
- The solution matrix
$$u$$ as a 2D plot. - Quiver plots to show the gradient field.
- Reordered sparse matrix visualizations (Cuthill-McKee and AMD).
This project demonstrates proficiency in:
- Numerical methods for partial differential equations.
- Efficient use of MATLAB for scientific computing.
- Sparse matrix handling for large-scale problems.
The project can be expanded to include:
- Adaptive grid refinements.
- Non-uniform source terms and more complex boundary conditions.
- Performance analysis and comparisons of iterative methods.
Author: Joel Amir Dario Maldonado Tänori
Date: October 2024
Contact: Email
This project is licensed under the MIT License. See the LICENSE file for more details.
I am passionate about numerical methods, algorithm development, and applied mathematics. If you're interested in collaborating or have questions, please reach out or check out my other projects.