0
$\begingroup$

I want to Plot Derivatives of ODE system.

n = 10;
T = 20;
r = 1.4;
A1 = 1;
A2 = 0.01;
RPT = 5;
IC = Table[RandomReal[{$MachineEpsilon, 1}, n], {j, RPT}];
eqns = Table[{x[i]'[t] == 
     x[i][t] (r - 
        A1 x[i][t] - (Sum[A2 x[k][t] Boole[i != k], {k, n}]) ), 
    x[i][0] == IC[[j]]}, {j, RPT}, {i, n}];
vars = Table[x[i][t], {j, RPT}, {i, n}];
vars2 = Table[Derivative[x[i][t], t], {j, RPT}, {i, n}]

sol = Table[NDSolve[eqns[[j]], vars[[j]], {t, 0, T}], {j, RPT}];


Table[Plot[Evaluate[vars[[j]] /. sol[[j, 1]]], {t, 0, T}, 
  PlotRange -> All, PlotStyle -> Automatic], {j, RPT}]

The graph of the derivative does not work well.

Table[Plot[Evaluate[vars2[[j]] /. sol[[j, 1]]], {t, 0, T}, 
  PlotRange -> All, PlotStyle -> Automatic], {j, RPT}]

Can anybody help me?

$\endgroup$
  • $\begingroup$ Definition of vars2 is apparently wrong, Derivative[x[i][t], t] just doesn't make sense. $\endgroup$ – xzczd Feb 9 at 9:05
3
$\begingroup$

It is necessary to separate the components of the solution, for example

n = 10;
T = 20;
r = 1.4;
A1 = 1;
A2 = 0.01;
RPT = 5;
IC = Table[RandomReal[{$MachineEpsilon, 1}, n], {j, RPT}];
eqns = Table[{x[j][i]'[t] == 
     x[j][i][t] (r - 
        A1 x[j][i][t] - (Sum[A2 x[j][k][t] Boole[i != k], {k, n}])), 
    x[j][i][0] == IC[[j]]}, {j, RPT}, {i, n}];
vars = Table[x[j][i][t], {j, RPT}, {i, n}];
vars2 = Table[D[x[j][i][t], t], {j, RPT}, {i, n}];

sol = NDSolve[eqns, vars, {t, 0, T}];
sol2 = NDSolve[eqns, vars2, {t, 0, T}];

Table[Plot[Evaluate[vars[[j]] /. sol], {t, 0, T}, PlotRange -> All, 
  PlotStyle -> Automatic], {j, RPT}]
Table[Plot[Evaluate[vars2[[j]] /. sol2], {t, 0, T}, PlotRange -> All, 
  PlotStyle -> Automatic], {j, RPT}]

fig1

$\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.