# Effect of boundary condition on the local error

Any error analysis is based on the Taylor expansions. So, if I take a finite difference scheme, I can calculate the value of the function at any point using the known value at another node via Taylor. However, if I am "at the edge" of the domain, the value of the function is fixed by the boundary condition, so how to deal with that? For example, inside of the domain I can say $$\frac{f(x+h)-f(x-h)}{2h}=f'(x)+Ch^2$$ So my question is how the boundary condition affects the Taylor expansion for the calculation of the local error?

As you correctly pointed out, the two point central scheme for FD is second order local, which makes it first order globally. The important point I think you are missing, is that in a FD scheme with specified values at the edges of your spacial mesh, you are always inside the domain. You should never have to approximate a first derivative at the boundary since the value is known. If you aren't evaluating your DE at the boundary, you don't have to worry about your error since there isn't any.

Now, if you have second order spacial derivatives, for other types of boundary conditions, things can get more complicated since you have to make sure a biased scheme at the edge is at least as high of order as your interior schemes.

EDIT: Looking at your comments on other answers, here is where I think you are being hung up.

When you are analyzing a standard interior node, you end with

$\frac{f(x+h)-f(x-h)}{2h}=f'(x)+O(h^2)$

so you have 2nd-order local error. You got to this point by using the taylor expansion

$f(x+h) = f(x) + f'(x)h + \frac{f''(x)h^2}{2} + H.O.T.$

and a similar expansion for the left hand neighbor. Now imagine you are at a node directly next to the boundary where you have a specified function value. The expansion

$g =f(x+h) = f(x) + f'(x)h + \frac{f''(x)h^2}{2} + H.O.T.$

still holds true. Your previous analysis still applies with the added information, because your approximation of the first derivative assumed you could accurately evaluate the function at the left and right neighbors. The fact that you are given $g$ is irrelevant, because you are already acting like you were given $f(x+h)$ and $f(x-h)$. Hopefully this is a bit clearer for you.

• correct, I am not trying to calculate the derivative at the point of the boundary, but the one before the boundary. Then, it would depend on the value of the boundary, even though it is officially inside of the domain. – Kamil Oct 15 '12 at 1:23
• exactly, so the analysis does not change. The taylor expansion already assumes you have a perfect evaluation of the function at each adjacent node. If anything the error would be less next to the edge, because you know the true value, rather than having accumulated error through time stepping or other sources. – Godric Seer Oct 15 '12 at 1:35
• I updated my answer with quite a bit more detail. Please let me know if anything isn't clear – Godric Seer Oct 15 '12 at 11:37

You can use the boundary conditions very easy in your scheme. If you have Dirichlet boundary conditions, which means specifying the values at the boundaries, you just use them instead of $f(x+h)$ or $f(x-h)$.

The accuracy of your scheme might degrade only if you have complex formed boundaries (i.e. curvy boundaries in 2D). Then you must use a Shortley-Weller scheme, which is only first order accurate.

• Assume it is a right boundary and $f(x+h):=g$. By Taylor $$f(x-h)=f(x)-f'(x)h+0.5f^{''}(x)h^2+O(h^2)$$ However, before I could do the same for $f(x+h)$. Now it is fixed and $$\frac{f(x+h)-f(x-h)}{2h}=\frac{g-f(x)+f'(x)h-0.5f^{''}(x)h^2}{2h}+O(h^2)$$ and, therefore, it doesn't look as before and I can't say it is an approximation for the derivative. What am I missing? – Kamil Oct 15 '12 at 1:25
• In the example you give, you are not "at the boundary" but rather a distance $h$ from it. Then $f(x+h)$ still has the usual Taylor expansion; nothing prohibits you from using it. – David Ketcheson Oct 15 '12 at 5:41