I am using Mathematica from around 10 months. I want to solve numerically a system of equations with number of equations more than 35 to 40. System of equations is shown below for small number of equations and with simplified form.

$$\begin{pmatrix} x1''\\x2''\\x3''\\x4''\\x5'' \end{pmatrix} + M_{(5 \times 5)} \begin{pmatrix} x1\\x2\\x3\\x4\\x5 \end{pmatrix} + V1_{(5 \times 1)} xb'' + V2_{(5 \times 1)} xb = 0, \\ \\ \text{and } \;\;\; xb=G (x5- \alpha x5^3) \cos \Omega t$$

Here, xb is calculated from one of the vector elements x5 itself. I have written the code (as shown below) where xb is a given function and it is not very difficult.

   V1={{1},{2},{3},{4},{5}};  f=5;
    s = NDSolve[{x''[t] + M.x[t] ==V1*f*Sin[t],x[0] == {1, 1, 1, 1}, x'[0] == {1, 1, 1, 1}}, x, {t, 0, 8}]

Here, f=5 (constant) I have taken, but actually f=f(x5) and that actually makes the system of equation complete. If I use f=x[[5,1]] than I get error, Part::partd: Part specification x[[5,1]] is longer than depth of object.

Can someone tell me, how I can address the element of variable vector using NDSolve for introducing $xb=G (x5- \alpha x5^3) \cos \Omega t$.

  • $\begingroup$ You can use Indexed[x[t], 5] instead, but you will have to work around taking derivatives of such objects. $\endgroup$
    – Carl Woll
    Nov 3, 2019 at 15:36

1 Answer 1


I think the Numerical Method of Lines Tutorial demonstrates a relatively clean way of setting up your type of problem.

You did not define $\alpha$, $G$, $\Omega$, $M$ or $V2$, so I chose arbitrary and uninteresting values (coupled systems are very easy to make unstable). Here is an example workflow:

n = 5;
f = 5;
G = 1;
alpha = 1;
omega = 1/10;
V1 = Flatten@{{1}, {2}, {3}, {4}, {5}};
V2 = {1, -1, 3, -1, 1};
X[t_] = Table[Subscript[x, i][t], {i, 1, n}];
Xb[t_] = G (Subscript[x, 5][t] - alpha 5^3 X[t]) Cos[omega*t];
M = -(ConstantArray[1, {n, n}] - 
     Table[KroneckerDelta[i, j], {i, 1, n}, {j, 1, n}]);
eqns = Thread[
   D[X[t], t, t] + M.X[t] + f*V1.D[Xb[t], t, t] + V2.Xb[t] == 
    ConstantArray[0, n]];
initc = Thread[X[0] == Table[1, {n}]];
initcp = Thread[(D[X[t], t]) == Table[1, {n}]] /. t -> 0;
system = Join[eqns, initc, initcp];
s = NDSolve[system, X[t], {t, 0, 8}];
Plot[Evaluate[X[t] /. First@s], {t, 0, 8}]

NDSolve Plot

  • $\begingroup$ M, V1 are Matrix and vector 5*5 and 5*1 respectively. Arbitrary values can be taken to check problem. Actually their order is more than 20. $\endgroup$
    – Hari
    Nov 3, 2019 at 15:11
  • $\begingroup$ I added some uninteresting arbitrary values. It was very easy to make the system go unstable with "random" arbitrary values. $\endgroup$
    – Tim Laska
    Nov 3, 2019 at 15:59
  • $\begingroup$ Thanks.. It is working perfectly and it is stable also with properly given values. $\endgroup$
    – Hari
    Nov 5, 2019 at 14:11
  • $\begingroup$ But, when the method is applied with NDSolveValue (to get value at specific t), it gives error "No functions were specified for output from NDSolveValue" and without the Subscript usage, NDSolveValue works fine for a group of equations. Any idea?? $\endgroup$
    – Hari
    Nov 6, 2019 at 11:42

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.