# Using NDSolve to solve non-linear ODEs

I am trying to solve the following ODE using Mathematica:

0=-f''[r]-(3/r)f'[r]+f[r]-3/2 f[r]^2 + a/2 f[r]^3

with the boundary conditions f'[0]=0 and f[r->infty]=0. a is just a number between 0 and 1.

I am quite new to Mathematica so am not sure of the technical details but I am currently using NDSolve. According to a paper that I have lifted the equation from, this is solved using the shooting method and 4th order Runge-Kutta; however, I thought NDSolve would do this for me. My Mathematica code is

f[r] /. NDSolve[{-f''[r] - 3/r f'[r] + f[r] - 3/2 f[r]^2 + a/2 f[r]^3 == 0, f'[0.1] == 0, f[120] == 0}, f[r], {r, 0.1, 120}][[1]]

which outputs an Interpolating Function which is just a horizontal line at the x-axis, which is clearly wrong. Can anyone help please?

• Parameter a isn't defined, that's why NDSolve doesn't evaluate! Jul 19 '19 at 13:48
• Why do you think the solution is wrong? You are saying the solution is zero at $\infty$ and slope is zero at the other end. So zero solution does satisfy the ODE. (replace $f(r)$ by zero) you get $0=0$. Doe the paper shows other solutions? Jul 19 '19 at 13:49
• @Nasser At r=0, I just require the first derivative df/dr=0. I understand that f(r)=0 is a solution, but it's trivial. I think I phrased wrong to say that it's the "wrong" solution; more, it's not a very interesting solution and I know there exist other solutions Jul 19 '19 at 13:56
• Your boundary conditions correspond to the trivial solution. Naturally, it is this solution that will be returned. Did this equation come from phase transition theory? Jul 19 '19 at 14:00
• @AlexeiBoulbitch it is, in vacuum decay in field theory. The aim is to solve this to calculate f(r) which is the solution to the classical equations of motion. There is then the trivial solution, which it is outputting. The paper I am reading says the method is forward/backward shooting with 4th order R-K in order to match the boundary conditions. I assumed that this is how NDSolve worked; is there a way I can explicitly say for it not to consider the trivial solution? Jul 19 '19 at 14:05

Here is an idea for how set up to a different initial seeding that then gives a non-zero solution.

res = NDSolveValue[{-f''[r] - 3/r f'[r] + f[r] - 3/2 f[r]^2 +
1/2 f[r]^3 == 0, f[120] == 0}, f, {r, 0, 120},
Method -> {"FiniteElement",
"MeshOptions" -> "MaxCellMeasure" -> 1},
InitialSeeding -> {f[r] == 0.25}];
Plot[res[r], {r, 0, 120}, PlotRange -> All]


For more ideas see also this answer. But in general changing the initial seeding to find solutions can be very challenging.

• Ok thanks. So then the boundary conditions are correct and I have a non-trivial solution. How then, using this method, does one find the 'correct' solution. The one I have in the paper is more like a step function such that the values of f[r] are always positive. I don't really understand how, if I didn't have the solution beforehand, how I would be able to tell which solution to use Jul 19 '19 at 14:47
• @ArchieCable, I would not conclude that just because the BCs work with an InitialSeed that they are the correct BCs for the problem your are trying to solve. And yes, nonlinear DEs can be tricky. Jul 19 '19 at 14:58
• So how would one go about finding the correct solution via this method? Jul 19 '19 at 15:03
• @ArchieCable As I have done in the answer I linked to: try a less nonlinear problem and use that as a starting value. Better understand the physics of the DE you want to solve. Make sure the DE and BCs are correct. Jul 19 '19 at 15:06