# Plot a system of differential equations in a loop

**URL:** <https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719>\
**Category:** Questions\
**Tags:** calculus, equation-solving, graphics-and-visualization, numerical-computation\
**Created:** [March 2, 2021, 7:11pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719 "2021-03-02T19:11:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![indianos2302](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@indianos2302](https://community.wolfram.com/u/indianos2302)\
**Post date:** [March 2, 2021, 7:11pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/1 "2021-03-02T19:11:27Z")

</div>

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.

[Code1 alt.nb](https://community.wolfram.com/uploads/short-url/kBt5hmjh7jRHwTqEiqpb4vNHZZz.nb) (284 KB)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [March 3, 2021, 5:37pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/2 "2021-03-03T17:37:04Z")

</div>

Agapi,

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

---

<div class="post-metadata">

**Author:** ![indianos2302](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@indianos2302](https://community.wolfram.com/u/indianos2302)\
**Post date:** [March 3, 2021, 5:59pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/3 "2021-03-03T17:59:03Z")

</div>

Thank you.  
I have corrected the post so as to use the same symbols as the code.

---

<div class="post-metadata">

**Author:** ![dontdont9](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dontdont9](https://community.wolfram.com/u/dontdont9)\
**Post date:** [March 3, 2021, 7:39pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/4 "2021-03-03T19:39:43Z")

</div>

Try

```
Plot[{
Sol1[[1,1]][s],Sol1[[1,2]][s],
Sol1[[2,1]][s],Sol1[[2,2]][s],
Sol1[[3,1]][s],Sol1[[3,2]][s],
Sol1[[4,1]][s],Sol1[[4,2]][s]},{s,0,smax}]

```

Then, if you really need to, you can modify that a tiny bit at a time and verify it works after each tiny change.

---

<div class="post-metadata">

**Author:** ![indianos2302](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@indianos2302](https://community.wolfram.com/u/indianos2302)\
**Post date:** [March 4, 2021, 9:42am UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/5 "2021-03-04T09:42:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dontdont9](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dontdont9](https://community.wolfram.com/u/dontdont9)\
**Post date:** [March 4, 2021, 11:07am UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/6 "2021-03-04T11:07:45Z")

</div>

A bit automated in what way?

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

---

<div class="post-metadata">

**Author:** ![indianos2302](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@indianos2302](https://community.wolfram.com/u/indianos2302)\
**Post date:** [March 4, 2021, 12:05pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/7 "2021-03-04T12:05:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dontdont9](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dontdont9](https://community.wolfram.com/u/dontdont9)\
**Post date:** [March 4, 2021, 12:29pm UTC](https://community.wolfram.com/t/plot-a-system-of-differential-equations-in-a-loop/17719/8 "2021-03-04T12:29:52Z")

</div>

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.
