# Solving a system of differential equations

I have three differential equations that I'm trying to solve for but Mathematica keeps returning my input as the output without solving them. Why is it not solving the equations? Is there an error in my code?

Solution = DSolve[{n1'[t] == A21*n2[t] + (r*Exp[-((t - 2)/0.1)^2])*(n3[t] - n1[t]),
n2'[t] == A32*n3[t] - A21*n2[t], n3'[t] == -A32* n3[t] - (r*Exp[-((t - 2)/0.1)^2]) (n3[t] - n1[t]),
n1[0] == 100, n2[0] == 0, n3[0] == 0}, {n2[t], n1[t], n3[t]}, t]

• Are you certain that there exists a closed-form solution for this system?
– user49048
Commented May 20, 2021 at 13:25
• Maple fails with it. Commented May 20, 2021 at 13:45
• DSolve returns unevaluated, when it cannot obtain a solution. Provide values for the constants and rry NDSolve. Commented May 20, 2021 at 14:18

eqns = {
n1'[t] == A21*n2[t] + (r*Exp[-(10 (t - 2))^2])*(n3[t] - n1[t]),
n2'[t] == A32*n3[t] - A21*n2[t],
n3'[t] == -A32*n3[t] - (r*Exp[-(10 (t - 2))^2]) (n3[t] - n1[t]),
n1[0] == 100, n2[0] == 0, n3[0] == 0};

Solution =
ParametricNDSolve[eqns, {n2, n1, n3}, {t, 0, 10}, {A21, A32, r}]


Manipulate[
Plot[Evaluate[
(#[A21, A32, r] /. Solution)[t] & /@
{n1, n2, n3}], {t, 0, 10},
PlotPoints -> 50,
MaxRecursion -> 5,
WorkingPrecision -> 15,
PlotLegends -> Placed[{n1, n2, n3}, {.125, .5}]],
{{A21, 0.25}, 0, 5, 0.1,
Appearance -> "Labeled"},
{{A32, 2.5}, 0, 5, 0.1,
Appearance -> "Labeled"},
{{r, 5}, 0, 5, 0.1,
Appearance -> "Labeled"}]


EDIT: To plot one function against another use ParametricPlot

Manipulate[
ParametricPlot[Evaluate[
(#[A21, A32, r] /. Solution)[t] & /@ {n1, n2}],
{t, 0, 10},
PlotPoints -> 50,
MaxRecursion -> 5,
WorkingPrecision -> 15,
Frame -> True,
FrameLabel -> (Style[#, 14, Bold] & /@
{"n1(t)", "n2(t)"}),
ColorFunction -> Function[{n1, n2, t},
ColorData["Rainbow"][t]],
PlotLegends -> BarLegend[{"Rainbow", {0, 10}},
LegendLabel -> Style["t", 14, Bold]],
AspectRatio -> 1],
{{A21, 0.25}, 0, 5, 0.1, Appearance -> "Labeled"},
{{A32, 2.5}, 0, 5, 0.1, Appearance -> "Labeled"},
{{r, 5}, 0, 5, 0.1, Appearance -> "Labeled"}]


• I wanted to plot n2-n1 of the solutions. How can I change your code to do this?
– CHA
Commented May 20, 2021 at 22:38
• Can I use parametric plot to plot (n2-n1) Vs time?So subtracting (n2-n1) I mean
– CHA
Commented May 20, 2021 at 23:04
• Just use Plot and change the argument to Evaluate[Subtract @@ ((#[A21, A32, r] /. Solution)[t] & /@ {n2, n1})] Commented May 20, 2021 at 23:09