In the process of typing up this question, I determine its solution. Since I went through the trouble of typing up the question in its entirety, I will post its answer as well. It may help out others who find themselves in the same predicament. Think of this as a sort of blog-post, if you will.

The Goal

Consider the mixed boundary value problem \begin{align} \frac{d}{dx}\left(k(x)\frac{du}{dx}\right)=f \text{ in }\Omega\\ u=P \text{ at } x=0\\ \frac{du}{dx}=T \text{ at } x=1 \end{align} where $P$ and $T$ are constants and $f$ is a source term.

I'm using finite differences and my goal is to impose the boundary condition at $x=1$ in such a way as to achieve second order accuracy. Assume that the grid has $N+1$ equispaced points (including the boundary points) given as $x_0,x_1,...,x_N$

My Approach

At the right boundary, use a 2nd order centered difference for the boundary condition \begin{equation} \frac{u_{N+1}-u_{N-1}}{\Delta x}=T\end{equation}

and the 2nd derivative operator as: \begin{align} \frac{k_{N+\frac{1}{2}}\frac{u_{N+1}-u_{N}}{\Delta x} -k_{N-\frac{1}{2}}\frac{u_{N}-u_{N-1}}{\Delta x}}{\Delta x}=f_i\end{align}

We can solve for the ghost point $U_{N+1}$ in the 1st equation, substitute it into the 2nd equation and simplify.

The Problem

Using this discretization requires the evaluation of $k_{N+\frac{1}{2}}=k(x_N+\frac{\Delta x}{2})$, which is outside of the domain! In general, $k(x)$ is only defined within the domain and I can't/shouldn't use values outside of it. Thus, I don't think this is the right approach to achieve 2nd order accuracy. What else can I do in this case?

  • 1
    $\begingroup$ The physically correct boundary conditions for this equation are $k \partial u/\partial x=T$ and this is how you should discretize it. $\endgroup$ Commented Jun 17, 2013 at 22:25
  • $\begingroup$ @WolfgangBangerth: Very true. If the boundary condition were given as $k(x)\frac{\partial u}{\partial x}=T$, then would it be advisable to multiply $k(x_N)$ to the discretization below? $\endgroup$
    – Paul
    Commented Jun 17, 2013 at 23:39
  • $\begingroup$ You mean to the formula below "My approach"? If so, yes! $\endgroup$ Commented Jun 18, 2013 at 12:13
  • $\begingroup$ @WolfgangBangerth: Actually, I was referring to the discretization technique in my answer, not the question :) $\endgroup$
    – Paul
    Commented Jun 18, 2013 at 12:49
  • $\begingroup$ Yes, there too. $\endgroup$ Commented Jun 18, 2013 at 19:23

1 Answer 1


Forget about discretizing the 2nd derivative operator since it requires evaluating at points outside the domain. Instead, just adjust the stencil for the boundary condition to use points $u_{N},u_{N-1},$ and $u_{N-2}$. By using standard method of undetermined coefficients, you can produce the coefficients necessary to achieve 2nd order accuracy. If i'm not mistaken, the discretized boundary condition in this case turn out to produce

$$\frac{du}{dx}\approx\frac{-\frac{1}{2}u_{N-2} +2u_{N-1} -\frac{3}{2}u_N}{\Delta x}=T$$

  • $\begingroup$ It appears you missed a sign in your equation. I'm assuming it's positive, but since you have obviously done the derivation more recently than me, I will let you correct it. $\endgroup$ Commented Jun 17, 2013 at 19:06
  • $\begingroup$ @GodricSeer: Indeed! I have adjusted it. $\endgroup$
    – Paul
    Commented Jun 17, 2013 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.