poisson_1d, a MATLAB code which solves a discretized version of the Poisson equation -uxx = f(x) on the interval a ≤ x ≤ b, with Dirichlet boundary conditions u(a) = ua, u(b) = ub. The linear system is solved using Gauss-Seidel iteration.
The 1D Poisson equation is assumed to have the form
-u''(x) = f(x), for a < x < b u(a) = ua, u(b) = ub
Let K be a small positive integer called the mesh index, and let N = 2^K be the corresponding number of uniform subintervals into which [A,B] is divided. Assigning a value U(I) to each of the N+1 equally spaced nodes with coordinate X(I), we approximate the equation by
-U(i-1) + 2 U(i) - U(i+1) ------------------------- = f( X(i) ), 1 < I < N+1 h^2 U(1) = ua, U(N+1) = ub.
It remains to solve the linear system for the desired values of U. This could be done directly, or iteratively. An iterative method such as Jacobi, Gauss-Seidel or SOR might be suitable, but experience shows that the convergence rate of these iterative methods decreases drastically as the value of K is increased - that is, as a more refined and accurate answer is sought.
The information on this web page is distributed under the MIT license.
poisson_1d is available in a C version and a C++ version and a Fortran77 version and a Fortran90 version and a FreeFem++ version and a MATLAB version and an Octave version and a Python version.
cg, a MATLAB code which implements the conjugate gradient method for solving a positive definite sparse linear system A*x=b.
cyclic_reduction, a MATLAB code which solves a tridiagonal linear system using cyclic reduction.
fd1d_bvp, a MATLAB code which applies the finite difference method to a two point boundary value problem in one spatial dimension.
gauss_seidel, a MATLAB code which uses the Gauss-Seidel iteration to solve a linear system with a symmetric positive definite (SPD) matrix.
jacobi, a MATLAB code which uses the Jacobi iteration to solving a system of linear equations with a symmetric positive definite (SPD) matrix.
mgmres, a MATLAB code which applies the restarted GMRES algorithm to solve a sparse linear system, by Lili Ju.
poisson_1d_multigrid, a MATLAB code which applies the multigrid method to a discretized version of the 1D Poisson equation.
poisson_2d, a MATLAB code which computes an approximate solution to the Poisson equation in a rectangle, using the finite difference method (FDM) and Jacobi iteration.
sor, a MATLAB code which implements the successive over-relaxation (SOR) method for the iterative solution of a linear system of equations.