# Numerical solution to Differential equation

I want to get the differential solution numerically. I used wolfram alpha. here is the link.

I tried this code on the Mathematica file.

sols4 = 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.00001] == -1.1024724270140055}, x[r], {r, 0.00001, 100},
Method -> "BDF"];
Plot[Evaluate[x[r] /. sols4], {r, 0.00001, 100}]


It makes me able to get the solution. But I also need a parametric plot as mentioned in wolfram alpha. How I can have that plot? Additionally, as I am using a shooting method and I need a solution to be zero at infinity. Can anyone tell me how I can avoid oscillation at large distances?

Thanks.

• ParametricPlot[{x[r] /. First@sols4, D[x[r] /. First@sols4, r]} // Evaluate, {r, 0.00001, 100}] Sep 12, 2019 at 17:03
• Thank you very much. It worked. Do you have any idea that how I can get rid of oscillation at r>20? I need solution to be zero as like it is before r=20. Sep 12, 2019 at 17:12
• I'm sorry but I don't understand your question. The solution is the solution. Are you talking about modifying your model so that it does that or defining a new function that is the solution above until $r=20$ and then zero afterward? (And what do you mean by zero? Do you mean it's at the origin after that or that the vertical component is zero?) Sep 12, 2019 at 17:35
• Actually, my differential equation is a boundary value problem. With x[0.0001]=Pi and x[infinity]=0. So I used the shooting method and converted it into an initial value problem with x[0.0001]=Pi and x'[0.0001]=-(some guessed value). But my gussed value gives oscillation at large distance. But I need x[infinity]=0 not oscillation. Sep 12, 2019 at 17:42
• You are changing the question. Please open a new question that includes both the code above and the boundary condition at large r that you are trying to match. My guess is that you are trying to match a separatrix at large r', which typically is difficult but possible numerically. Sep 12, 2019 at 18:27

sols4 = NDSolveValue[{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.00001] == -1.1024724270140055}, x, {r, 0.00001, 100},
Method -> "BDF"];

Plot[sols4[r], {r, 0.00001, 100}] For a parametric plot use ParametricPlot

ParametricPlot[
{sols4[r], sols4'[r]}, {r, 0.00001, 100}]
` 