Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

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}]

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

For more examples check here: ParametricNDSolve.

share|improve this answer
    
Is there a way to plot multiple solutions on the same graph as opposed to each parameter set generating a whole new plot? –  Megan Mar 4 at 17:14
    
@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. –  Szabolcs Mar 4 at 17:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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