Group Abstract Group Abstract

Message Boards Message Boards

Plot a system of differential equations in a loop

Posted 4 years ago

Hello, I am having a problem to plot a system of two differential equations while one initial value is assigned values from a Table. This is my code

g = 5/3;

c4 = 6;

smax = 10;

Rinit = 1.05;

Linit = 0.5;

t = Flatten@Table[Linit + i, {i, 0, 0.3, 0.1}];

Sol1 = NDSolveValue[{D1[s] == 
      2 (-1 + R[s]) R[
        s] (-(-1 + g) L[s] + 
         c4 ((-1 + R[s]) R[s]^3)^((1 - g)/2) (-2 + g) g L[s]^(2 - g) +
          c4 ((-1 + R[s]) R[s]^3)^((1 - g)/2) (-1 + g) g L[s]^-g), 
     N1[s] == -(1 + L[s]^2) (1 - g + 
         c4 (-1 + R[s])^(1/2 - g/2)
           R[s]^(-(3/2) (-1 + g)) (2 + 4 R[s] (-1 + g) - 3 g) g L[s]^(
          1 - g)), R'[s] == D1[s]/(\[Sqrt](D1[s]^2 + N1[s]^2)), 
     Derivative[1][L][s] == N1[s]/(\[Sqrt](D1[s]^2 + N1[s]^2)), 
     R[0] == Rinit, L[0] == #, 
     WhenEvent[
      D1[s] == 0, {smax = s, Print[N1[s]/D1[s]], "StopIntegration"}, 
      "DetectionMethod" -> "DerivativeSign"]}, {R, L}, {s, 0, 
     smax}] & /@ t

(*s1=ParametricPlot[Evaluate@Through[Sol1[{R[s],L[s]}]],{s,0,smax},\
PlotStyle\[Rule]Red,AxesLabel\[Rule]{R,L},AspectRatio\[Rule]Full,\
PlotRange\[Rule]All]*)

(*ParametricPlot[{Rsol[s],Lsol[s]},{s,0,smax},PlotStyle\[Rule]Red,\
AxesLabel\[Rule]{R,L},AspectRatio\[Rule]Full,PlotRange\[Rule]All]*)

I think there is a mistake on the ParametricPlot, but I am not sure. I have included the file. Thank you.

Attachments:
POSTED BY: Agapi Pop
7 Replies
Posted 4 years ago

If you can be more specific and precise about what you mean by "a bit more automated or efficient" then someone might be able to offer some idea.

POSTED BY: Bill Nelson
Posted 4 years ago

Fair enough, but this is the starting point of something else I am trying to do. I might need to scan through hundreds of points and compare the results, first by plotting. That is why I am trying to do it a bit more automated or efficient if you like. Thank you again for finding the time to answer my question.

POSTED BY: Agapi Pop
Posted 4 years ago

A bit automated in what way?

If you can provide more detail about what you want then someone might be able to help.

POSTED BY: Bill Nelson
Posted 4 years ago

Thank you very much. Is there a way to make the procedure a bit automated? I would like to be able to change the step and not having to type all these plots

POSTED BY: Agapi Pop
Posted 4 years ago
POSTED BY: Bill Nelson
Posted 4 years ago
POSTED BY: Agapi Pop
Posted 4 years ago

Agapi,

The code in the attached notebook does not match the code in the question. The usage of Through is incorrect. Check the documentation.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard