# How to vary finite difference approximation order in NDSolve at boundaries

According to here, NDSolve, when using the method of lines, creates partial derivatives in the spacial coordinate (lets talk just about one spacial coordinate for now) using the finite difference approximations, eg

$\left.\frac{\partial}{\partial x}f(x)\right|_{x_i} \approx \frac{-f(x_{i-1})+f(x_{i+1})}{2h} + \mathcal O(h^2)$

where $h = x_j -x_{j-1}$. This approximation is good to the second order (ie $h^2$). There are approximations that take more datapoints and give higher order.

Similarly, there are asymmetrical ones that NDSolve uses for the (non periodic) endpoints.

My question is this: How do I set the order of the approximation that I want NDSolve to use? In particular, how do I set it at the endpoints? I have a set of equations that is highly sensitive to the boundary conditions.

• have you seen the documentation (here)[reference.wolfram.com/language/tutorial/… which is also available in the local documentation center. I think it contains everything you might or might not want to know about the Method of Lines as used in Mathematica :-). To begin, there is the "SpatialDiscretication" option for the MethodOfLines method with which you should be able do what you want (and probably much more). The documentation has some usage examples... Jun 8, 2015 at 12:53
• The documentation, which is the same that I referenced in my question, vexingly, does not have any examples in the section about the difference order pertaining how to implement it. However, by cobbling together the other examples I have found that setting "DifferenceOrder" for the "SpacialDiscritization" works. Does this do the bounadries, though? Jun 8, 2015 at 13:01
• You can see what NDSolve does with NDSolveFiniteDifferenceDerivative, e.g. this example from the tutorial is symbolic: NDSolveFiniteDifferenceDerivative[1, {Subscript[x, -1], Subscript[x, 0], Subscript[x, 1]}, {Subscript[f, -1], Subscript[f, 0], Subscript[ f, 1]}, "DifferenceOrder" -> 2]. You can use a different grid and function values to see other orders. Is that the sort of information you are looking for? Other examples on this site: mathematica.stackexchange.com/… Jun 8, 2015 at 13:24
• Sorry, I didn't see that you had that reference in your question. I can not answer your question about boundaries, at least not without reading through the documentation once more, which I have no time for, sorry... Jun 8, 2015 at 21:02
• You might attract more attention if the title were "How to get a varying difference order in NDSolve?" or "How to set a different difference order at the boundary in NDSolve?" The title, as it stands, has a simple answer ("DifferenceOrder"), and users familiar with NDSolve might think it's not an interesting question. Jun 11, 2015 at 16:24

As far as I can glean, NDSolve can use whatever "DifferenceOrder" you wish, but the order will be the same throughout and the spatial discretization will be uniform.