I am trying to numerically integrate a system of nonlinear differential equations.

Say for simplicity it is $\dot x_1 = x_2, \dot x_2 = (1-x_1) x_2$. I hand this to NDSolve as

NDSolve[{X'[t] == { X[t][[2]], (1-X[t][[1]])X[t][[2]] }, X[0] == {1,1} }, X[t], {t,0,1}]

However I run into a problem as X[t][[1]] evaluates to t and NDsolve integrates the different equation $\dot x_1 = x_2, \dot x_2 = (1-t) x_2$.

Is their a simple way around this problem? More generally is their a way to stop Part from taking function arguments, but instead to only act as a vector index?

I know in this case I could just write system explicitly, but in the case I am studying the dimensionality of the system is not known when writing the code, and we have X'[t] == f[X[t]] where f is a function that returns a vector of nonlinear combinations of the parts of X[t] according to a pattern. Hold prevents Part evaluating (which is good) however it also prevents fevaluating (which is bad).

  • 4
    $\begingroup$ Try NDSolve[{x'[t] == {Indexed[x[t], 2], (1 - Indexed[x[t], 1]) Indexed[x[t], 2]}, x[0] == {1, 1}}, x, {t, 0, 1}]. $\endgroup$ Apr 24, 2017 at 2:34
  • $\begingroup$ Gar, that looks like basic knowledge I should have had, but it has made my life so much easier. If you put it as an answer I will accept it. $\endgroup$ Apr 24, 2017 at 3:06

1 Answer 1


As J.M. pointed it out, if you want to refer to variables of a vectorial ODE, use Indexed as the symbolic counterpart of Part.

     x'[t] == {Indexed[x[t], 2], (1 - Indexed[x[t], 1]) Indexed[x[t], 2]},     
     x[0] == {1, 1}}, x, {t, 0, 1}]

Note, that it is the initial condition that explicitly tells NDSolve that the dynamical system is vector-valued.


Your Answer

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

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