0
$\begingroup$

I have a Manipulate plot and want to add another function, in addition to the existing a and e. The existing code is as follows:

SetOptions[Plot, Frame -> True, Axes -> False, 
   LabelStyle -> {FontFamily -> "Arial", FontSize -> 12, Bold}, 
   FrameStyle -> Directive[Thick, Black], ImageSize -> Medium]; 

Constants

au = QuantityMagnitude[UnitConvert[Quantity[1, "AstronomicalUnit"], "Meters"]]; 
c = QuantityMagnitude[UnitConvert[Quantity[1, "SpeedOfLight"], "MetersPerSecond"]]; 
Qpr = 1; 
Lsun = QuantityMagnitude[UnitConvert[Quantity[1, "SolarLuminosity"], "Watts"]]; 
Rsun = QuantityMagnitude[UnitConvert[Quantity[1, "SolarRadius"], "Meters"]]; 
Msun = QuantityMagnitude[UnitConvert[Quantity[1, "SolarMass"], "Kilograms"]]; 
G = QuantityMagnitude[UnitConvert[Quantity[1, "GravitationalConstant"], 
     ("Meters"^2*"Newtons")/"Kilograms"^2]]; 
year = QuantityMagnitude[UnitConvert[Quantity[1, "Years"], "Seconds"]]; 
Myr = year*10^6; 
Gyr = year*10^9; 
Mwd = 0.6*Msun; 
Cst = 1.27; 
U = 1*10^17; 

Functions

L[t_] := (3.26*Lsun*(Mwd/(0.6*Msun)))/(0.1 + t/Myr)^1.18; 
Roche[dens_] := (0.65*Cst*Rsun*(Mwd/(0.6*Msun))^(1/3))/(dens/3000)^3^(-1); 
Papsis[t_] := a[t]*(1 - e[t]); 

Radiative Drag

RDdadtRρa = -((3*L[t]*Qpr*(2 + 3*e[t]^2))/(c^2*(16*Pi*2000*Rast*a[t]*(1 - e[t]^2)^(3/2)))); 
RDdedtRρa = -((15*L[t]*e[t])/(c^2*(32*Pi*Rast*2000*a[t]^2*Sqrt[1 - e[t]^2]))); 

RDsolRρa = ParametricNDSolveValue[{Derivative[1][a][t] == RDdadtRρa, 
     Derivative[1][e][t] == RDdedtRρa, a[0] == a0, e[0] == 3/10}, {a, e}, {t, 0, 9*Gyr}, 
    {Rast, ρ, a0}]; 

fRDticks = {{Automatic, Automatic}, {Charting`FindTicks[{0, 1}, {0, 1/Myr}], Automatic}}; 

Manipulate[Plot[RDsolRρa[Rast, ρ, a0*au][[func]][t], {t, 0, 9*Gyr}, FrameTicks -> fRDticks], 
  {{func, 1}, {1 -> "a", 2 -> "e"}}, {{Rast, 0.005}, 0.0001, 0.1, 0.001, Appearance -> "Labeled"}, 
  {{ρ, 3000}, 1000, 7000, 50, Appearance -> "Labeled"}, {{a0, 10, "a0 (au)"}, 3, 20, 0.2, 
   Appearance -> "Labeled"}]

I want to add a further plot, which is defined as: q=a(1-e), where a and e are already plotted. Any help is appreciated.

$\endgroup$
2
  • $\begingroup$ you can define q[a_,e_]:=a (1-e) outside Manipulate[...] and then insert the q[a,e] function into Manipulate. This would normally work. $\endgroup$ Commented Feb 6, 2021 at 20:16
  • $\begingroup$ I've defined the function Papsis in the above code, but I don't know how to add it into my current Manipulate function and have another tab, in addition to a and e on the plot which shows Papsis plotted. Sorry I'm relatively new to Mathematica. $\endgroup$
    – testing09
    Commented Feb 6, 2021 at 20:33

2 Answers 2

3
$\begingroup$

I introduced the function fun and TrackedSymbols-{..} as well as {{func, 1}, {1 -> "a", 2 -> "e", 3 -> "q"}} into the Manipulate. The rest is the same. The changed Manipulate:

Manipulate[
 fun[sel_, t_] := 
  Switch[sel, 1, RDsolR\[Rho]a[Rast, \[Rho], a0*au][[1]][t], 2, 
   RDsolR\[Rho]a[Rast, \[Rho], a0*au][[2]][t], 3, 
   RDsolR\[Rho]a[Rast, \[Rho], a0*au][[1]][
     t] (1 - RDsolR\[Rho]a[Rast, \[Rho], a0*au][[2]][t])];
 
 Plot[fun[func, t], {t, 0, 9*Gyr}, 
  FrameTicks -> fRDticks], {{func, 1}, {1 -> "a", 2 -> "e", 
   3 -> "q"}}, {{Rast, 0.005}, 0.0001, 0.1, 0.001, 
  Appearance -> "Labeled"}, {{\[Rho], 3000}, 1000, 7000, 50, 
  Appearance -> "Labeled"}, {{a0, 10, "a0 (au)"}, 3, 20, 0.2, 
  Appearance -> "Labeled"}, 
 TrackedSymbols -> {func, Rast, \[Rho], a0}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Amazing! Thank you so much. One last question- is it possible to scale the y axis of a and q only, such that it is in au i.e. divide all ticks by au? When I attempt this, the e y axis scales with it, which is not what I want. $\endgroup$
    – testing09
    Commented Feb 7, 2021 at 12:06
0
$\begingroup$

To change units according to the selection, we use the same trick as above. We define a function scale that returns the appropriate scale factor:

Manipulate[
 fun[sel_, t_] := 
  Switch[sel, 1, RDsolR\[Rho]a[Rast, \[Rho], a0*au][[1]][t], 2, 
   RDsolR\[Rho]a[Rast, \[Rho], a0*au][[2]][t], 3, 
   RDsolR\[Rho]a[Rast, \[Rho], a0*au][[1]][
     t] (1 - RDsolR\[Rho]a[Rast, \[Rho], a0*au][[2]][t])];
 scale[sel_] := Switch[sel, 1 | 3, au, 2, 1];
 
 Plot[fun[func, t]/scale[func], {t, 0, 9*Gyr}, 
  FrameTicks -> fRDticks], {{func, 1}, {1 -> "a", 2 -> "e", 
   3 -> "q"}}, {{Rast, 0.005}, 0.0001, 0.1, 0.001, 
  Appearance -> "Labeled"}, {{\[Rho], 3000}, 1000, 7000, 50, 
  Appearance -> "Labeled"}, {{a0, 10, "a0 (au)"}, 3, 20, 0.2, 
  Appearance -> "Labeled"}, 
 TrackedSymbols -> {func, Rast, \[Rho], a0}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.