1
$\begingroup$

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]
$\endgroup$
3
  • 2
    $\begingroup$ Are you certain that there exists a closed-form solution for this system? $\endgroup$ May 20 at 13:25
  • 2
    $\begingroup$ Maple fails with it. $\endgroup$
    – user64494
    May 20 at 13:45
  • 2
    $\begingroup$ DSolve returns unevaluated, when it cannot obtain a solution. Provide values for the constants and rry NDSolve. $\endgroup$
    – bbgodfrey
    May 20 at 14:18
3
$\begingroup$

Use ParametricNDSolve

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

enter image description here

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

enter image description here

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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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