1
$\begingroup$

How could I plot parameters Br and Dr for several values of t0 starting from -3 to 0 with step size 1 for the following ode? I was able to plot t0=-3 and want to plot other lists of parameter set {Br,Dr } derived from different points of t0 in the same graph.

ClearAll["Global`*"];
t0 = -3; b = 2;

ode1 = y'[t] == -Sin[x[t]]/y[t];

ode2 = x'[t] == -Cos[x[t]] (6 Sin[x[t]] Cos[x[t]] + y[t] (b - c (1 + 3*y[t]^2)))/(2*
   y[t]^3*(b + c (y[t]^2 - 1)));

ode3 = v'[t] == -(b + c*(y[t]^2 - 1))/(4*y[t]*Cos[x[t]]) + Sin[x[t]]/(2*y[t]^2);

bc = {x[t0] == 0, y[t0] == Br, v[t0] == Log[Dr]};
sol = ParametricNDSolve[{ode1, ode2, ode3, bc}, {x, y, v}, {t, t0,0}, {c, Br, Dr}]
 data = Table[FindRoot[{(y[c, Br, Dr][0] - 1) /. sol, v[c, Br, Dr][0] /. sol}, {{Br,1}, {Dr, 1}}], {c, 0.3, 2.2, .05}];
Br = Br /. data; Dr = Dr /. data;

ListLinePlot[Thread[{Dr, ArrayResample[Br, Length@Dr]}],Frame -> True, FrameLabel -> {{"Br", ""}, {"Dr", ""}}]
$\endgroup$
2
  • $\begingroup$ Do you mean to plot several data in one Plot? $\endgroup$ Sep 20, 2022 at 3:36
  • $\begingroup$ I meant another set of Br and Dr data from the table for another values of t0 and show them altogether in a same graph. $\endgroup$
    – Dibbo123
    Sep 20, 2022 at 14:40

1 Answer 1

0
$\begingroup$

We can use Do loop as follows

ClearAll["Global`*"];
b = 2;

ode1 = y'[t] == -Sin[x[t]]/y[t];

ode2 = x'[
    t] == -Cos[
      x[t]] (6 Sin[x[t]] Cos[x[t]] + y[t] (b - c (1 + 3*y[t]^2)))/(2*
       y[t]^3*(b + c (y[t]^2 - 1)));

ode3 = v'[t] == -(b + c*(y[t]^2 - 1))/(4*y[t]*Cos[x[t]]) + 
    Sin[x[t]]/(2*y[t]^2);

bc = {x[t0] == 0, y[t0] == Br, v[t0] == Log[Dr]};


Do[t0 = -3 + i/2; 
 sols[i] = 
  ParametricNDSolve[{ode1, ode2, ode3, bc}, {x, y, v}, {t, t0, 0}, {c,
     Br, Dr}]; 
 dat[i] = 
  Table[{Br, Dr} /. 
     FindRoot[{(y[c, Br, Dr][0] - 1) /. sols[i], 
       v[c, Br, Dr][0] /. sols[i]}, {{Br, 1}, {Dr, 1}}] // Quiet, {c, 
    0.3, 2.2, .05}]; 
 lst[i] = 
  Thread[{dat[i][[All, 2]], 
    ArrayResample[dat[i][[All, 1]], Length@dat[i]]}], {i, 0, 5, 1}]

Visualization

ListPlot[Table[lst[i], {i, 0, 5, 1}], Frame -> True, 
 FrameLabel -> {{"Br", ""}, {"Dr", ""}}, 
 PlotLegends -> Table[Row[{"t0 =", -3. + i/2}], {i, 0, 5, 1}]] 

Figure 1

$\endgroup$
4
  • $\begingroup$ Thank you so much @Alex Trounev. This is what I was looking for. $\endgroup$
    – Dibbo123
    Sep 20, 2022 at 16:01
  • $\begingroup$ You are welcome! $\endgroup$ Sep 20, 2022 at 16:03
  • $\begingroup$ @Dibbo123 Question about solution mark is very advanced. Better to start new post. Maybe somebody has a good answer. $\endgroup$ Sep 22, 2022 at 15:18
  • $\begingroup$ Thanks. I will do that. $\endgroup$
    – Dibbo123
    Sep 22, 2022 at 15:30

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.