Boundary Conditions
Boundary Conditions
Boundary Conditions
A 1-d Example. Recall that when we applied finite difference discretization to the 1-d
Poisson equation on the unit interval
d2 u
= f (x),
dx2
0<x<1
(1)
where ui u(xi ). Eqn (1) was derived earlier with equispace grid points xi = ih, i =
1, . . . , N and with homogeneous Dirichlet boundary conditions. By setting u0 = u(0) = 0
and uN +1 = u(xN +1 ) = u(1) = 0, we obtained from (1) the matrix-vector equation
Au = b
where A = tridiag(1, 2, 1) is N N and u and b have entries
[u]i = ui ,
[b]i = h2 fi ,
i = 1, . . . , N.
h2 f1 + , if i = 1,
if i = 2, . . . , N 1,
[b]i = h2 fi ,
2
h fN + , if i = N.
The coefficient matrix A remains unchanged, and the length of the vector u remains the
same.
Neumann Boundary Conditions. Suppose the left boundary condition is Neumann,
du
(0) = .
dx
The minus sign before the derivative is chosen for consistency with the 2-d case below. There
are several candidates for the difference approximation to apply to the derivative in this case,
1
but we take the centered difference approximation about x0 = 0 because it is second order
accurate (Eqn (1) is also based on a second order approximation). This yields
u(x1 ) u1
= + O(h2 ).
2h
(2)
Note that we made use of a ghost grid point, x1 = h. If we drop the O(h2 ) error term,
substitue the approximations ui u(xi ), and solve for the approximation at the ghost grid
point, we obtain
u1 = u1 + 2h .
(3)
We next add the grid point x0 = 0 to the computational grid h = {ih | i = 1, . . . , N }.
Applying the difference equation (1) for index i = 0 and substituting eqn (3) gives
2u0 2u1 = 2h + h2 f0 .
(4)
This gives rise to several changes in the system Au = b. The length of the vectors u and
b is now N + 1 rather than N , and the matrix A is N + 1 N + 1. The vector b now has
entries
(
h2 f0 + 2h, if i = 0,
[b]i =
h2 f i ,
if i = 1, . . . , N.
The matrix A is still tridiagonal, but the entries on the superdiagonal are no longer constant.
In particular,
[A]0,1 = 2,
[A]i,i+1 = 1 for i = 1, . . . , N 1.
(5)
The entries of the main diagonal are all 2, and the subdiagonal entries are all -1.
Neumann Boundary Conditions in 2-d. To illustrate, consider the 2-d Poisson equation
on the unit square with Neumann boundary conditions on the left boundary,
u n =
u
= (0, y),
x
0 < y < 1,
(6)
and homogeneous Dirichlet boundary conditions on the rest of the boundary. Recall the finite
difference approximation to the Poisson equation on a regular grid with uj,k u(jh, kh),
4uj,k uj1,k uj+1,k uj,k1 uj,k+1 = h2 f (xj , yk ).
(7)
k = 1, . . . , Nx .
Taking the index j = 0 in eqn (7) and substituting u1,k from eqn (8) gives
4u0,k 2u1,k u0,k1 u0,k+1 = h2 f0,k + 2h0,k ,
2
k = 1, . . . , Nx .
(8)
Exercises
1. Outline the finite difference implementation of Poissons equation on the unit interval
in 1-d with Neumann boundary conditions at the right endpoint. Provide explicit
formulas for the entries of the coefficient matrix A and the right-hand-side vector b.
2. Derive a second order accurate finite difference approximation to Robin, or third kind,
boundary conditions in one space dimension. Provide formulas for the entries of the
coefficient matrix A and the right-hand-side vector b for Poissons equation on the unit
interval with Robin boundary conditions on the left boundary.