Skip to main content
1 of 2
Mariusz Iwaniuk
  • 16.6k
  • 1
  • 27
  • 46

Another way:

eps = 10^-10; end = 10;
sol[n_] := NDSolve[
{g'[r] == a[r]*g[r]/r, a'[r]/r == g[r]^2 - 1, a[eps] == n, g[end] == 1}
,{a[r], g[r]}, {r, eps, end}, Method -> {"Shooting", 
"StartingInitialConditions" -> {a[end] == eps, g[end] == (1 - eps)}}];

Plot[Evaluate[g[r] /. sol[#] & /@ {1, 2, 5, 10}], {r, eps, end}, 
PlotLegends -> {"n=1", "n=2", "n=5", "n=10"}, PlotLabels -> "g(r)"]
Plot[Evaluate[a[r] /. sol[#] & /@ {1, 2, 5, 10}], {r, eps, end}, 
PlotRange -> All, PlotLegends -> {"n=1", "n=2", "n=5", "n=10"}, 
PlotLabels -> "a(r)"]

enter image description here

Mariusz Iwaniuk
  • 16.6k
  • 1
  • 27
  • 46