Error in boundary condition corrected
To solve this ODE system, begin by determining its behavior near r == 0
.
Series[{g'[r] - (a[r] g[r])/r, a'[r]/r + 1 - g[r]^2}, {r, 0, 2}] // Normal;
Thread[Flatten@CoefficientList[r % /. a[0] -> n, r] == 0];
Solve[%, {a'[0], a''[0], a'''[0], a''''[0], g[0], g'[0], g''[0], g'''[0]}]
(* a'[0] -> 0, a''[0] -> -1, a'''[0] -> 0, a''''[0] -> 0,
g[0] -> 0, g'[0] -> 0, g''[0] -> 0, g'''[0] -> 0 *)
In other words, g[r]
vanishes to all orders at the origin for most values of n
. However, if n
is a positive integer, the same set of commands leaves Derivative[n][g][0]
undetermined. So, g[eps]
is approximately proportional to eps^n
. Next, solve the equations numerically by shooting, using the method previously employed here and elsewhere on this site. (As noted in my comment above, DSolve
returns unevaluated when applied to these equations.) A typical calculation for n == 5
is given by
eps = 10^-5; end = 20;
sp = ParametricNDSolveValue[{g'[r] == a[r] g[r]/r, a'[r]/r == g[r]^2 - 1,
a[eps] == n0, g[eps] == eps^n0 gp,
WhenEvent[g[r] > 101/100, {bool = 1, "StopIntegration"}],
WhenEvent[a[r] < 0, {bool = 0, "StopIntegration"}]},
{a[r], g[r]}, {r, eps, end + 5}, {gp, wp0, n0},
WorkingPrecision -> wp0, Method -> "StiffnessSwitching"];
bl = 0; bu = 2; imax = 100; wp = 75; n = 5;
Do[bool = -1; bmiddle = (bl + bu)/2; st = sp[bmiddle, wp, n];
rm = (First[st] /. r -> "Domain")[[1, 2]];
If[bool == 0, bl = bmiddle, bu = bmiddle]; ip = i;
If[bool == -1, Return[]], {i, imax}];
s[n] = st;
For larger values of n
, wp
must be increased. For instance, with n = 10
, wp = 90
is required. Results for n = {1, 2, 5, 10}
are plotted below.
Plot[{s[1], s[2], s[5], s[10]}, {r, eps, 10}, PlotRange -> All, AxesLabel -> {r, "a, g"},
ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}]
The solutions takes no more than several seconds each.
DSolve
does not produce an error message but instead returns unevaluated, meaning that it cannot solve the problem.. $\endgroup$sol := proc (n) options operator, arrow; dsolve([(D(g))(r) = a(r)*g(r)/r, (D(a))(r)/r = g(r)^2-1, a(1/100000) = n, g(10) = 1], numeric) end proc;plots:-display(seq({plots:-odeplot(sol(n), [r, g(r)], linestyle = n, color = ColorTools:-Color([1/n, 1/(1+n), 1/(n+4)]))}, n = 1 .. 7));plots:-display(seq({plots:-odeplot(sol(n), [r, a(r)], linestyle = n, color = ColorTools:-Color([1/n, 1/(1+n), 1/(n+4)]))}, n = 1 .. 7));
$\endgroup$