Abitatha Roy
Abitatha Roy

Reputation: 93

Tag list is protected in Mathematica

I am trying to run the following code in Mathematica.

Sol1 = DSolve[{S'[t] == D - Er - Es*S[t], S[0] == 1}, S[t], t]

plots = Table[
  Evaluate[
   S[t] /. Sol1 /. {D -> d, Er -> er, Es -> es}], {{d, er, 
    es}, {{10, 5, 5}, {10, 4, 3}, {6, 4, 4}}}]

Plot[plots, {t, 0, 10}, 
 PlotLegends -> {"D = 10, Er = 5, Es = 5", "D = 10, Er = 4, Es = 3", 
   "D = 6, Er = 4, Es = 4"}]

I get the following error.

[![enter image description here](https://i.sstatic.net/QseoHHin.png)](https://i.sstatic.net/QseoHHin.png)

Any insights on why this is being caused and what could be potential fixes with respect to my code is appreciated.

Expectation: Three plots to be generated on the graph.

Upvotes: 1

Views: 46

Answers (1)

Chris Degnen
Chris Degnen

Reputation: 8655

Table only uses one iterator, e.g.

Table[x, {x, {{1, 2}, {3, 4}, {5, 6}, {7, 8}}}]

and doesn't allow

Table[{x, y}, {{x, y}, {{1, 2}, {3, 4}, {5, 6}, {7, 8}}}]

One way to iterate over your inputs would be

Sol1 = DSolve[{S'[t] == D - Er - Es*S[t], S[0] == 1}, S[t], t]

plots = Function[{d, er, es},
   S[t] /. Sol1 /. {D -> d, Er -> er, Es -> es}] @@@
  {{10, 5, 5}, {10, 4, 3}, {6, 4, 4}}

Plot[plots, {t, 0, 10},
 PlotLegends -> {"D = 10, Er = 5, Es = 5", "D = 10, Er = 4, Es = 3",
   "D = 6, Er = 4, Es = 4"}]

enter image description here

Upvotes: 0

Related Questions