I have a parameter set list and I would like to solve a system of ODEs multiple times using each parameter set in the list. Then I would like each set of solutions to be graphed on the same plot.

For example:

I have imported this list of parameter sets:

{{ "a", "b", "c", "d"}, {1, 5, 1, 3}, {2, 3, 2, 2}, {3, 3, 3, 1}}

Then I have this system

system={x'[t] == a*x[t] + b*y[t], y'[t] == c*x[t] + d*y[t], x[0] == 10, y[0] == 0};

I would like to substitute each parameter set in for a,b,c,d respectively, then solve using

sol = DSolve[system, {x[t], y[t]}, {t}] 

for each parameter set (or NDSolve, ParametricNDSolve if appropriate)

Then I would like all sets of solutions to be plotted on the same graph

Plot[{x[t] /. sol, y[t] /. sol}, {t, 0, 7}, PlotRange -> Automatic].

Note, I would like to use this example to understand the process and apply it to a larger system with more parameters and a larger list of sets of parameters.


1 Answer 1


This is the procedure. Just ask if you have questions regarding details.

params = {{1, 5, 1, 3}, {2, 3, 2, 2}, {3, 3, 3, 1}}

sol = ParametricNDSolve[system, {x, y}, {t, 0, 10}, {a, b, c, d}]

 Plot[{(x @@ p)[t], (y @@ p)[t]} /. sol // Evaluate, {t, 0, 10}],
 {p, params}

For more examples check here: ParametricNDSolve.

  • $\begingroup$ Is there a way to plot multiple solutions on the same graph as opposed to each parameter set generating a whole new plot? $\endgroup$
    – Megan
    Mar 4, 2014 at 17:14
  • $\begingroup$ @Megan Yes, but that leads to other questions, for example, how do you differentiate the datasets? How do you separately differentiate x from y? It would lead to code which mostly deals with plot styling, so I suggest you ask a separate and specific question about that. If you apply Show[..., PlotRange->All] to the table, it will combine them to a single plot but won't give a useful result for the reason I state it. $\endgroup$
    – Szabolcs
    Mar 4, 2014 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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