# Misleading character of numerical solutions to ODE when compared with closed-form solution: how to avoid?

I've previously mentioned this combination of an ordinary differential equation and boundary and far-field conditions. $$g''\left(x\right)+3g'\left(x\right)+2g\left(x\right) = \exp\left(-3x\right)$$ $$g\left(0\right) = 0$$ $$\lim_{x \to +\infty}\left(g'\left(x\right)\right) = 0$$

The far-field condition actually doesn't impose any constraint on the solution, which therefore contains an arbitrary constant $$G$$: $$g\left(x\right) = \frac{1}{2}\exp\left(-3x\right)+G\exp\left(-2x\right)-\left(G+\frac{1}{2}\right)\exp\left(-x\right)$$ As a result, $$g'\left(0\right)$$ can take any value (it's $$-G-1$$).

Now imagine that I don't know how to construct the closed-form solution. Maybe I try a finite-difference shooting method. But I can't finite-difference-shoot all the way to infinite $$x$$, so I apply the far-field condition at some large, finite value of $$x$$, call it $$X$$: $$g''\left(x\right)+3g'\left(x\right)+2g\left(x\right) = \exp\left(-3x\right)$$ $$g\left(0\right) = 0$$ $$g'\left(X\right) = 0$$

This forces a specific value on $$G$$, $$G = \left(-\exp\left(-X\right)+3\exp\left(-3X\right)\right)/\left(2\exp\left(-X\right)-4\exp\left(-2X\right)\right)$$, and therefore on $$g'\left(0\right)$$, $$g'\left(0\right) = \left(-\exp\left(-X\right)+4\exp\left(-2X\right)-3\exp\left(-3X\right)\right)/\left(2\exp\left(-X\right)-4\exp\left(-2X\right)\right)$$. Worse, this has a well-defined limit as $$X \to +\infty$$, $$g'\left(0\right) = -1/2$$, so I would be misled into thinking the original problem with the far-field condition at infinity imposes a fixed value of $$g'\left(0\right)$$. How would I avoid being misled in this way?

(Something I've already tried: a change of independent variable to $$y = \exp\left(-3x\right)$$ to map the problem onto a finite domain, but the resulting differential equation has a singular point at $$y = 0$$, which is problematic for the finite-difference integration.)

(It won't come as any surprise that what I'm really trying to solve is a more complicated - fifth-order, nonlinear - differential equation, to which I really don't know a closed-form solution, but the issue I've got is closely analogous to this.)

• In my opinion, what you call being "misled" cannot be avoided. You can only discretize on bounded domains. That's the uncertainty you have when not computing the exact solution. When you discretize a partial differential equation for example, you will always have to define a boundary condition, whereas the analytical solution always has the same behavior at $\pm \infty$. This especially happens with reaction-diffusion-equations Commented May 13 at 19:18
• Guessing rarely ever helps. You could also try to control $g(X)$ rather than $g'(X)$.... Commented May 13 at 19:43
• If you have 5 derivatives, you can also control many points at the boundary. Unfortunately, there is no sure fire way :( However, maybe you find 5 values of the function that you know, then you can get the correct initial/boundary conditions Commented May 13 at 20:18
• Yes, maybe you should ask again with the ODE explicitly stated. Right now, I don't know what I can do for you :( Commented May 15 at 7:22
• Thanks @HyperbolicPDEfriend. I've done that (although the ODE I've explicitly stated is the version after the change of independent variable that maps it onto a bounded domain). Commented May 15 at 13:33