1
$\begingroup$

I have a system of differential equations where I want to get a numerical plot for certain initial conditions. I want to keep A2 and M2 as constants but see how its values changes my plot. However I am getting errors and Mathematica always crushes when I try to plot. I have tried several methods, but for a0 it gives wrong plot.

Thanks!

eqn = {r0[t] == 3 /a0[t]^3,
   r2[t] == (5 (M2* a0[t] - 3 *a2[t]))/(
    2 a0[t]^3 Derivative[1][a0][t]^2),
   Derivative[1][a0][t]^2 == 1 + 1/a0[t],
   Derivative[1][a2][t] == (M2 *a0[t] - a2[t])/(
    2 a0[t]^2 Derivative[1][a0][t]),
   a0[1] == 1,
   a2[1] == A2,
   r0[1] == 3,
   r2[1] == (5 (-3 A2 + M2))/4};
X = ParametricNDSolveValue[eqn, {a0, r0, a2, r2}, {t, 0, 2}, {M2, A2}]
Manipulate[
 ParametricPlot[Evaluate@Through[X[M2, A2][[1]][t]], {t, 0, 2}], {M2, 
  0, 1}, {A2, 0, 1}]

enter image description here

X = ParametricNDSolveValue[{a0'[t] == Sqrt[M01/a0[t] + 1], 
   a0[1] == 1}, a0, {t, 0, 2}, {M01}]
Manipulate[Plot[X[M01][t], {t, 0, 2}, PlotRange -> All], {M01, 0, 2}]

UPDATE!!! When I run proposed solution I got this plot:

enter image description here

$\endgroup$
8
  • $\begingroup$ Welcome. Usually we prefer to have code in a copy-pasteable form here rather than screenshots and photos of your screen :-) $\endgroup$
    – user49048
    Feb 23, 2022 at 14:44
  • 1
    $\begingroup$ @DiSp0sablE_H3r0 I apologize, just updated, now you can copy. $\endgroup$ Feb 23, 2022 at 14:50
  • $\begingroup$ I have found a mistake. When I call X[M2, A2][[1]][t]], I call for M2[t], not a0 as I wanted. Is there anyway to get a0[t] out from parametric function. $\endgroup$ Feb 23, 2022 at 14:52
  • $\begingroup$ Thanks for updating the OP. I am about to start a skype in a bit so I don't have the time to look into it now. I'll try to get back to it later $\endgroup$
    – user49048
    Feb 23, 2022 at 14:57
  • $\begingroup$ Try e.g. X[1,1] and look at the error messages. $\endgroup$ Feb 23, 2022 at 15:03

1 Answer 1

0
$\begingroup$
Clear["Global`*"]

eqn = {r0[t] == 3/a0[t]^3,
   r2[t] == (5 (M2*a0[t] - 3*a2[t]))/(2 a0[t]^3 a0'[t]^2),
   a0'[t]^2 == 1 + 1/a0[t],
   a2'[t] == (M2*a0[t] - a2[t])/(2 a0[t]^2 a0'[t]),
   a0[1] == 1, a2[1] == A2, r0[1] == 3,
   r2[1] == (5 (-3 A2 + M2))/4};

X = ParametricNDSolveValue[eqn, {a0, r0, a2, r2},
   {t, 0, 2}, {M2, A2}];

Manipulate[
 Plot[X[M2, A2][[1]][t], {t, 0, 2}],
 {{M2, 0.75}, 0, 1, 0.01, Appearance -> "Labeled"},
 {{A2, 0.5}, 0, 1, 0.01, Appearance -> "Labeled"},
 SynchronousUpdating -> False,
 TrackedSymbols :> All]

enter image description here

$\endgroup$
7
  • $\begingroup$ I am running the same code, but getting different plot. What could be the problem? $\endgroup$ Feb 23, 2022 at 16:58
  • $\begingroup$ Try: Quit the kernel, copy and paste the above code into a notebook, execute the code. $\endgroup$
    – Bob Hanlon
    Feb 23, 2022 at 17:04
  • $\begingroup$ Did it several times, still getting something like Heaviside function $\endgroup$ Feb 23, 2022 at 17:11
  • $\begingroup$ The shape of the plot changes radically with the Manipulate control parameters. If comparing to above, you must have the same parameter settings in the Manipulate $\endgroup$
    – Bob Hanlon
    Feb 23, 2022 at 17:14
  • $\begingroup$ Can you look to the post? I updated and uploaded the screenshot of my plot. $\endgroup$ Feb 23, 2022 at 17:25

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.