Plotting the functions from ParametricNDSolveValue for system of differential equations

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}]


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:

• Welcome. Usually we prefer to have code in a copy-pasteable form here rather than screenshots and photos of your screen :-)
– user49048
Commented Feb 23, 2022 at 14:44
• @DiSp0sablE_H3r0 I apologize, just updated, now you can copy. Commented Feb 23, 2022 at 14:50
• 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. Commented Feb 23, 2022 at 14:52
• 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
– user49048
Commented Feb 23, 2022 at 14:57
• Try e.g. X[1,1] and look at the error messages. Commented Feb 23, 2022 at 15:03

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]


• I am running the same code, but getting different plot. What could be the problem? Commented Feb 23, 2022 at 16:58
• Try: Quit the kernel, copy and paste the above code into a notebook, execute the code. Commented Feb 23, 2022 at 17:04
• Did it several times, still getting something like Heaviside function Commented Feb 23, 2022 at 17:11
• 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` Commented Feb 23, 2022 at 17:14
• Can you look to the post? I updated and uploaded the screenshot of my plot. Commented Feb 23, 2022 at 17:25