0
$\begingroup$

I have the following code that works well.

rF = NDSolveValue[{r'[\[Phi]] == -(r[\[Phi]] - 1)^2/r[\[Phi]]/Sqrt[2] Sqrt[r[\[Phi]]^3 + r[\[Phi]]], r[0] == 10000}, r, {\[Phi], 0, 8 \[Pi]}]
PolarPlot[rF[\[Phi]], {\[Phi], 0, 8 \[Pi]}, PlotRange -> {{-2, 8}, {-2, 2}}]

I need to plot this for various r[0], but it doesn not work,

dats = Table[NDSolveValue[{r'[\[Phi]] == -(r[\[Phi]] - 1)^2/r[\[Phi]]/Sqrt[2] Sqrt[r[\[Phi]]^3 + r[\[Phi]]], r[0] == r0}, r, {\[Phi], 0, 8 \[Pi]}], {r0, 1, 11}];
plot = Plot[dats, {\[Phi], 0, 8 \[Pi]}, ColorFunction -> ColorData["Rainbow"], Frame -> True, ImagePadding -> 50, PlotRangeClipping -> False]

any help is very appreciated.

$\endgroup$
3
  • 1
    $\begingroup$ What do you mean by "It does not work"? It returns the input unevaluated? It made a plot but it's not what you expected? It spit out a bunch of errors? It returned an empty plot? Etc. Can you be more specific about what the problem is? $\endgroup$ Commented Aug 9 at 1:14
  • 3
    $\begingroup$ Replace dats by Through[dats[\[Phi]]] inside the Plot command. $\endgroup$ Commented Aug 9 at 1:16
  • 2
    $\begingroup$ Or use r[\[Phi]] as the value to return in NDSolveValue[] instead of just r. $\endgroup$ Commented Aug 9 at 1:38

1 Answer 1

2
$\begingroup$
$Version

(* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *)

rF = ParametricNDSolveValue[
   {r'[\[Phi]] == -(r[\[Phi]] - 1)^2/r[\[Phi]]/Sqrt[2] Sqrt[
       r[\[Phi]]^3 + r[\[Phi]]], r[0] == r0},
   r, {\[Phi], 0, 8 \[Pi]}, r0];

PolarPlot[
 Evaluate@Table[rF[r0][\[Phi]], {r0, 1, 11}], {\[Phi], 0, 8 \[Pi]},
 PlotStyle -> "Rainbow",
 PlotRangeClipping -> False,
 PlotRange -> All,
 Frame -> True,
 PlotLegends -> LineLegend[
   ColorData["Rainbow"] /@ Range[0, 1, 0.1],
   Range[11],
   LegendLayout -> {"Column", 2},
   LegendLabel -> Subscript[r, 0]],
 ImageSize -> 500]

enter image description here

EDIT: To selectively plot values of r0

Manipulate[plts = Sort[plts];
 colors = (ColorData["Rainbow"] /@ Range[0, 1, 0.1]);
 plt = PolarPlot[
   Evaluate@Table[rF[r0][\[Phi]], {r0, plts}], {\[Phi], 0, 8 \[Pi]},
   PlotStyle -> colors[[plts]],
   PlotRange -> {{-1.25, 11}, {-1.2, 1.55}},
   PlotRangePadding -> Scaled[.03],
   Frame -> True,
   PlotLegends -> LineLegend[colors[[plts]], plts,
     LegendLayout -> If[Length@plts > 5, {"Column", 2}, "Column"],
     LegendLabel -> Subscript[r, 0]],
   ImageSize -> 500],
 {{plts, Range[11], Subscript[r, 0]}, Range[11],
  ControlType -> TogglerBar},
 TrackedSymbols :> {plts}]
$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.