5
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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... $\endgroup$ – Albert Retey Jun 8 '15 at 12:53
  • $\begingroup$ 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? $\endgroup$ – rspencer Jun 8 '15 at 13:01
  • $\begingroup$ You can see what NDSolve does with NDSolve`FiniteDifferenceDerivative, e.g. this example from the tutorial is symbolic: NDSolve`FiniteDifferenceDerivative[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/… $\endgroup$ – Michael E2 Jun 8 '15 at 13:24
  • $\begingroup$ 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... $\endgroup$ – Albert Retey Jun 8 '15 at 21:02
  • 1
    $\begingroup$ 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. $\endgroup$ – Michael E2 Jun 11 '15 at 16:24
4
+25
$\begingroup$

This is a long comment, with pointers to what I hope are helpful resources and ideas. For me, developing an answer to this seems like a too long a project for me to undertake at this point. While I am curious to see a good solution, I have no personal interest in actually achieving it.

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.

I couldn't find any options manually set the spatial discretization in the tutorial, The Numerical Method of Lines. You can set the size of the grid but the actual grid points will be computed automatically and placed uniformly. The beginning of the tutorial shows how to manually set up the numerical method of lines. It seems possible that someone could adapt this approach to the OP's problem.

The Finite Element Method can be used for the spatial discretization and the method of lines used for the time integration for appropriate PDEs; see Transient PDEs. The spatial discretization can be set manually to any grid. This seems a different approach than what the OP has in mind, but I mention it in case it is an appropriate alternative.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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