# Part of an undefined function in NDSolve

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][], (1-X[t][])X[t][] }, X == {1,1} }, X[t], {t,0,1}]


However I run into a problem as X[t][] 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).

• Try NDSolve[{x'[t] == {Indexed[x[t], 2], (1 - Indexed[x[t], 1]) Indexed[x[t], 2]}, x == {1, 1}}, x, {t, 0, 1}]. – J. M.'s torpor Apr 24 '17 at 2:34
• 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. – ComptonScattering Apr 24 '17 at 3:06

## 1 Answer

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.

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


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