Many of the MATLAB programs linked below are from the Computational Science and Engineering ("CSE") Web site. Many more great MATLAB programs can be found there.

  • Four linear PDE solved by Fourier series: mit18086_linpde_fourier.m (M)
    Shows the solution to the IVPs u_t=u_x, u_t=u_xx, u_t=u_xxx, and u_t=u_xxxx, with periodic b.c., computed using Fourier series. The initial condition is given by its Fourier coefficients. In the example a box function is approximated.
  • Compute stencil approximating a derivative given a set of points and plot von Neumann growth factor: mit18086_stencil_stability.m (M)
    Computes the stencil weights which approximate the n-th derivative for a given set of points. Also plots the von Neumann growth factor of an explicit time step method (with Courant number r), solving the initial value problem u_t = u_nx.
    Example for third derivative of four points to the left:
    >> mit18086_stencil_stability (-3:0,3,.1)
  • Error convergence for the 1d Poisson equation: mit18336_poisson1d_error.m (M) (CSE)
    Sets up a sequence of 1d Poisson problems, and plots the error convergence on log-log scale.
  • Sets up and solves a sparse system for the 1d, 2d and 3d Poisson equation: mit18086_poisson.m (CSE)
    Sets up a sparse system by finite differences for the 1d Poisson equation, and uses Kronecker products to set up 2d and 3d Poisson matrices from it. The systems are solved by the backslash operator, and the solutions plotted for 1d and 2d.
  • Computes the LU decomposition of a 2d Poisson matrix with different node ordering: mit18086_fillin.m (CSE)
    Sets up a 2d Poisson problem and computes the LU decomposition of the system matrix, firstly with lexicographic ordering, then with red-black ordering and then with symamd ordering.
  • Demo for elimination with reordering: moe.m (M)
    Visualizes elimination with various reordering methods for a 2d Poisson problem. Reordering methods are reverse Cuthill-McKee, minimum degree, symamd, and nested dissection.
  • Computes the incomplete LU factorization of a 2d Poisson matrix for different tolerances: mit18086_ilu.m (CSE)
    Sets up a 2d Poisson problem and computes the LU factorization and the incomplete LU factorization for different tolerances. Run times, condition numbers and nonzero pattern are plotted for comparison.
  • Smoothing and convergence for Jacobi and Gauss-Seidel iteration: mit18086_smoothing.m (CSE)
    Sets up a 1d Poisson problem with an oscillatory right hand side and applies Jacobi and Gauss-Seidel iteration to it. One can observe how the error gets smoothed very quickly, but the actual convergence to the correct solution is very slow.
  • Multigrid solver for 1d Poisson problem: mit18086_multigrid.m (CSE)
    Sets up a 1d Poisson test problem and solves it by multigrid. The method uses two grid recursively using Gauss-Seidel for smoothing and elimination to solve at coarsest level. The number of pre- and postsmoothing and coarse grid iteration steps can be prescribed.
  • Conjugate gradient method for 2d Poisson problem: mit18086_cg.m (CSE)
    Sets up a 2d Poisson problem and solves the arising linear system by a conjugate gradient method. The error over iteration steps is plotted.
  • Finite differences for the one-way wave equation, additionally plots von Neumann growth factor: mit18086_fd_transport_growth.m (CSE)
    Approximates solution to u_t=u_x, which is a pulse travelling to the left. The methods of choice are upwind, downwind, centered, Lax-Friedrichs, Lax-Wendroff, and Crank-Nicolson. For each method, the corresponding growth factor for von Neumann stability analysis is shown.
  • Nonlinear finite differences for the one-way wave equation with discontinuous initial conditions: mit18086_fd_transport_limiter.m (CSE)
    Solves u_t+cu_x=0 by finite difference methods. Of interest are discontinuous initial conditions. The methods of choice are upwind, Lax-Friedrichs and Lax-Wendroff as linear methods, and as a nonlinear method Lax-Wendroff-upwind with van Leer and Superbee flux limiter.
  • Finite differences for the wave equation: mit18086_fd_waveeqn.m (CSE)
    Solves the wave equation u_tt=u_xx by the Leapfrog method. The example has a fixed end on the left, and a loose end on the right.
  • Level set method for front propagation under a given front velocity field: mit18086_levelset_front.m (CSE)
    Uses the level set method with reinitialization to compute the movement of fronts under a given velocity field.
  • Finite differences for the incompressible Navier-Stokes equations in a box: mit18086_navierstokes.m (CSE)
    Solves the 2D incompressible Navier-Stokes equations in a rectangular domain with prescribed velocities along the boundary. The standard setup solves a lid driven cavity problem.
    This Matlab code is compact and fast, and can be modified for more general fluid computations. You can download a Documentation for the program. (This resource may not render correctly in a screen reader.PDF)
  • Spectral methods for the incompressible Navier-Stokes equations on a torus: mit18336_spectral_ns2d.m (CSE)
    Solves the 2D incompressible Navier-Stokes equations in vorticity/stream function formulation on the torus, using spectral methods.