0
$\begingroup$

I have this system of differential equations :

$\frac{dX}{dt} = (0.8+0.4c_{1})X-(0.007+0.006c_{2})XY$

$\frac{dY}{dt} = (0.048+0.004c_{3})XY-(0.4+0.2c_{4})Y$

where $c_{i}$s are parameters.

I solve the system using the follwing code :

   sol = ParametricNDSolve[{x'[t] == (0.8 + 0.4 c1) x[t] - (0.009 + 0.002 c2) x[t] y[t], 
   y'[t] == (0.0049 + 0.0002 c3) x[t] y[t] - (0.4 + 0.2 c4) y[t], 
   x[0] == 200, y[0] == 80}, {x, y}, {t, 0, 25}, {c1, c2, c3, c4}]

I then set the parameter values as $c_{i}=\{0,1\}$ for $ i=1,2,3,4$. I tabulate the results using the following code :

xt = Flatten[Evaluate[Table[x[c1, c2, c3, c4][t] /.sol, 
            {c1, {0, 1}}, {c2, {0, 1}}, {c3, {0, 1}}, {c4, {0, 1}}]]] //MatrixForm

This gives the following output

enter image description here

Question 1 How do I know which InterpolatingFunction corresponds to which particular combination of $c_{i}$ ?

Now I evaluate all the InterpolatingFunction for $t=0(0.25)25$ using this code :

mat = Table[Table[Evaluate[xt[[a]]], {t, 0, 25, 2.5}], {a,Range[Length[xt]]}] // MatrixForm

giving the following output :

enter image description here

Question 2

Each row in the above matrix displays the evaluation of one of the InterpolatingFunction for $t=0(0.25)25$. I need to get the columnwise maximum(and minimum) for this matrix at $t=0,5,10,...,25$ and want to identify which InterpolatingFunction it comes from.

I got the maximum using

l = Min /@ Transpose[mat]

But couldn't identify which InterpolatingFunction the maximums come from.

Any help is appreciated.

$\endgroup$
  • 1
    $\begingroup$ Maybe something like Flatten[Table[{{c1, c2, c3, c4}, x[c1, c2, c3, c4][t] /.sol}, {c1, {0, 1}}, {c2, {0, 1}}, {c3, {0, 1}}, {c4, {0, 1}}], 3], then? $\endgroup$ – J. M. will be back soon Feb 1 '17 at 14:31
  • $\begingroup$ That does it. What does the 3 at the end do? And what about the second question? $\endgroup$ – Aritra Saha Feb 1 '17 at 14:33
  • $\begingroup$ "What does the 3 at the end do?" - at this point, what you should be doing instead is to look at the docs for Flatten[]. ;) $\endgroup$ – J. M. will be back soon Feb 1 '17 at 14:36
  • $\begingroup$ Yeah. I should do it myself. Thanks for the heads-up though. $\endgroup$ – Aritra Saha Feb 1 '17 at 14:45
1
$\begingroup$

One way to make the table from NDSolve is,

points = Permutations[{0, 1, 0, 1, 0, 1, 0, 1}, {4}];
datax = TableForm[Table[Flatten[{t,Table[{x[c1, c2, c3, c4][t] /. sol}, {c1, {0, 1}}, 
{c2, {0,1}}, {c3, {0, 1}}, {c4, {0, 1}}]}], {t, 0, 10, 0.5}], 
      TableHeadings -> {None, Prepend[Array["x", Length[points]], t]}]

enter image description here

datay = TableForm[Table[Flatten[{t,Table[{y[c1, c2, c3, c4][t] /. sol}, {c1, {0, 1}}, 
    {c2, {0,1}}, {c3, {0, 1}}, {c4, {0, 1}}]}], {t, 0, 10, 0.5}], 
          TableHeadings -> {None, Prepend[Array["y", Length[points]], t]}]

enter image description here

I don't know, how to make the headings for the column automated.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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