In this lecture, we will obtain solution of one dimensional diffusion and advection-dispersion equations using MATLAB. The partial differential equation (PDE) solver implemented by the "pdepe" function in MATLAB can be used to solve the diffusion and advection-diffusion equations. The MATLAB PDE solver solves initial-boundary value problems for systems of parabolic and elliptic partial differential equations in the one space variable x and time t. The solver converts the partial differential equations to ordinary differential equations using a second-order accurate spatial discretization, based on a fixed set of user-specified nodes. After discretization, differential equations give rise to algebraic equations.
The PDE solves systems of parabolic and elliptic partial differential equations in one spatial variable x and time t, of the form
![]() |
(37.1) |
The partial differential equations hold for t 0 ≤ t ≤ tf and a ≤ x ≤ b . The interval [a, b] must be finite. The m can be 0, 1, or 2, corresponding to slab, cylindrical, or spherical symmetry, respectively. In equation (37.1) f is a flux term and s
is the source term. The flux term must depend on ‘∂c/∂x'. The coupling of the partial derivatives with respect to time is restricted to multiplication by a diagonal matrix g
. The diagonal elements of this matrix are either identically zero or positive.
At the initial time t = t0, for all values of x, the solution components satisfy initial conditions of the form,
C(x, t0) = c0(x) | (37.2) |
At the boundary x = a or x = b, for all t, the solution components satisfy a boundary condition of the form given below.
![]() |
(37.3) |
The syntax of the "pdepe" function is
C = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan)
Where pdefunc is a handle to a function that defines the components of the PDE. The equation (37.1) is defined in this function. icfun is a handle to a function that defines the initial conditions. The initial condition given by the equation (37.2) is specified in this function. bcfun is a handle to a function that defines the boundary conditions (equation 37.3). The boundary conditions are defined in this function. xmesh is a vector specifying the points at which a numerical solution will be calculated for every value in tspan and tspan is a vector specifying the points at which a solution is will be obtained for every value in xmesh .
The pdefun computes and of equation 37.1. The syntax of the function is,
[g, f, s] = pedfun(x, t, c, dcdx)
The icfun evaluates the initial conditions. The syntax of icfun is
Where co returns the initial condition.
The bcfun calculates the terms of the boundary conditions specified in equation (37.3). The syntax of the function is
[pl, ql, pr, qr] = bcfun(xl, cl, xr, cr, t)
Where cl is the approximate solution at the left boundary xl and cr is the approximate solution at the right boundary xr. The pl and ql are column vectors corresponding to p and q of equation (37.3) evaluated at xl. Similarly pr and qr are column vectors corresponding to p and q of equation (37.3) evaluated at xr.
In the following section, the solution of the diffusion and advection-diffusion equation will be obtained using pdepe function.