# Can a second-order ODE be "inconsistent" with its boundary conditions?

I am trying to solve a set of coupled, nonlinear ODEs. The only dependent variable is a 1-dimensional spatial coordinate, let's call it $x$. For now, I've managed to approximate away some of the coupling between the equations, such that the first one doesn't depend on the second one at all. I solved it with FEM without major difficulty: boundary conditions met, residuals look good, physically meaningful result.

So now I'm left with one nonlinear, second-order ODE where the nonlinear coefficient functions are completely determined by the FEM solution, something like

$$\begin{cases} A(x) + B(x) f(x) + C(x) f'(x) + D(x) f''(x) = 0 \\ f(0) = f(1) = 0 \end{cases}$$

where $A$, $B$, $C$, and $D$ are known, at least at the resolution of the FEM mesh.

The problem is that, using the same basic code as before, the solution appears to violate the boundary conditions entirely, blowing up as $x \rightarrow 0$ instead of approaching zero (or even any finite value, it doesn't seem to matter what I choose). Thinking this was a problem with my code, I experimented with a finer mesh and with finite differences instead of finite elements, with no success. It finds the same nonsensical result every time.

Finally, I put my numerical data for the coefficients into Mathematica and attempted to solve the above BVP. I let it run for quite a while (maybe 15-30 minutes) before giving up. It never found a solution.

So finally, my question: Is it possible that this equation simply can't be solved with these boundary conditions? For example, I tried changing $f(1) = 0 \rightarrow f'(0) = 0$ and the solution was found almost instantaneously by Mathematica, but it still violated the new boundary condition; somehow, that didn't trigger an error, but it made me suspicious that something "bigger" might be going on here.

I'm looking for some mathematical intuition behind why the numerical methods might fail in these cases and how to mitigate these problems.

# Update

This equation is linear (correcting here so that comments still make sense). I think that's not the root of my problem, though; I tried using a linear solver with the proper stiffness matrix and load vector to solve $-f''(x) = g(x)$, which should be EASY; here, $g(x)$ is the FEM solution to the first equation. The solution meets boundary conditions but is "jagged" (think sawtooth patterns overlaid on a smooth function). Now I think perhaps there's something wrong with substituting the FEM solution for the first equation into the second equation, but I'm not sure why.

Not giving up yet.

# Update 2

I think I can safely rule out a problem with this code; I am generating the source files with SymPy, so there shouldn't be any human errors associated with changing functional forms, etc. of the equations I want to solve. As an example of what I'm seeing now, see figure below. The only intuition I have for this is that the code "tries" to meet boundary conditions (which are homogeneous Dirichlet), but the solution, for whatever reason, fundamentally wants to blow up to $-\infty$. So we end up with this "compromise" solution that straddles the two possibilities.

Is this even remotely correct? It doesn't seem to matter what I change at this point, and refining the mesh just increases the frequency of the sawtooth form. • Are you suggesting that the coefficients $A,B,C,D$ depend on $f$? Because the way you write the ODE would imply that it's linear. Aug 24, 2018 at 3:16
• @WolfgangBangerth, I was being thick, and you're absolutely right -- this equation is linear after all. (I should have said, "A, B, C, D are nonlinear functions of x," which obviously isn't the same thing.) Aug 24, 2018 at 18:41
• Then the equation should be well-posed unless $D(x)=0$ at some points $x$. If $D$ never changes sign and is, ideally, continuous, then there should not be a problem. Aug 24, 2018 at 20:17
• @WolfgangBangerth, suppose $D(x)$ can change signs (I'm honestly not sure either way, but I think it could), but is continuous. What kinds of problems could I expect to encounter? Sep 1, 2018 at 23:48
• Then you're in trouble -- you have an ODE that is posed on two parts of the domain separately but that are inconnected or connected only in some sense that requires additional conditions. Sep 3, 2018 at 13:42

Also your ODE is not nonlinear because $A(x)$, $B(x)$, $C(x)$, and $D(x)$ do not depend on $f$ itself and as a result it should be solved easily by simple linear finite element or finite difference solvers (e.g. scipy BVP solver).
• I just wanted to say that for every finite element or finite difference type methods, as long as you assemble their stiffness matrix (note: it's just a name for this type of linear matrix equations: $A \mathbf{x} = b$, where $A$ is called stiffness or mass matrix, $\mathbf{x}$ is the unknown vector, and $b$ is your response vector which could be assembled regarding to your boundary conditions and main ODE), you should get your imposed boundary conditions correct. Because the boundary conditions are the things that you imposed on the system and it's not related to the ODE itself.
• Of course, boundary conditions should make sense if you are trying to solve a physical problem, but from pure mathematical point of view, as long as you put your intended values for boundary conditions in the $A$ and $b$ you will get it correctly at vector $\mathbf{x}$. Otherwise you did not solve that linear equation correctly, which is a basis of finite element or finite difference type methods.