# Shooting Method for Numerical Solution

I am trying to solve the following nonlinear differential equation using the shooting method. The equation is a boundary value problem with boundary condition x=Pi and x[Infinity]=0. In order to avoid singularity, I am using x[0.0001]=Pi and x[xmax]=0. My solution is okay up to some finite value like it is zero but after it gives oscillation. I don't need these oscillation and need zero just like before the oscillation started. My code is

sols13 = NDSolve[{x''[
r] + (1/r) x'[r] - (0.5/r^2) Sin[2 x[r]] + (2/r) Sin[x[r]]^2 -
0.2 Sin[x[r]] - Sin[2 x[r]] == 0, x[0.00001] == Pi,
x == 0}, x[r], {r, 0.00001, 100},
Method -> {"Shooting",
"StartingInitialConditions" -> {x[0.00001] == Pi,
x'[0.00001] == -1.117876}}];
Plot[Evaluate[x[r] /. sols13], {r, 0.00001, 100},
AxesLabel -> {r, \[Theta][r]}, LabelStyle -> "Input",
PlotRange -> All]
ParametricPlot[{x[r] /. First@sols13, D[x[r] /. First@sols13, r]} //
Evaluate, {r, 0.00001, 100}, Frame -> True,
FrameLabel -> {\[Theta][r], \[Theta]'[r]}, LabelStyle -> "Input"]


I used a parametric plot to find the value of x'[0.0001] in order to get the desired plot.

• You appear to be trying to integrate along a separatrix, which always is numerically unstable. The best you can do with the shooting method is to integrate along the separatrix for a while, and then stop (say at r == 7). If for some reason you need to integrate further, improve your guess for x'[0.00001]. By the way, the large r solution you obtained is valid, except that it does not match the boundary condition at r == 100, as pointed out by the error messages you received. – bbgodfrey Sep 16 '19 at 19:09
• Thanks for the reply. – physicsu83 Sep 17 '19 at 14:21

## 1 Answer

The method of the false transient works well here

rmin = 10^-6; L = 10^2; nn = 2137; tmax = 10; X =
NDSolveValue[{D[x[r, t], r,
r] + (1/r) D[x[r, t], r] - (1/2/r^2) Sin[
2 x[r, t]] + (2/r) Sin[x[r, t]]^2 - 1/2 Sin[x[r, t]] -
Sin[2 x[r, t]] == D[x[r, t], t], x[rmin, t] == Pi, x[L, t] == 0,
x[r, 0] == Pi (L - r)/(L - rmin)}, x, {r, rmin, 100}, {t, 0, tmax},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> nn, "MaxPoints" -> nn, "DifferenceOrder" -> 4}},
MaxSteps -> 10^6]

{Plot3D[X[r, t], {r, rmin, 100}, {t, 0, tmax}, Mesh -> None,
ColorFunction -> Hue, AxesLabel -> Automatic],
Plot[X[r, tmax], {r, rmin, 100}, AxesLabel -> {r, \[Theta][r]},
LabelStyle -> "Input", PlotRange -> All],
ParametricPlot[{X[r, tmax], Derivative[1, 0][X][r, tmax]}, {r, rmin,
100}, Frame -> True, FrameLabel -> {\[Theta][r], \[Theta]'[r]},
LabelStyle -> "Input", AspectRatio -> 1/2, PlotRange -> All]} 