1

I have been able to solve some differential equations using Tables. The code works fine without errors. However, I am unable to plot the results. Any help would be appreciated.

n = 10;
initialx = Table[Subscript[x, i][0] == (i - 1)*0.1, {i, 1, 11}];
initialy = Table[Subscript[y, i][0] == 0, {i, 1, 11}];

eqnvx = Table[
Subscript[x, i]'[t] == (100*Subscript[x, i][t]), {i, 2, 10} ];
eqnvx1 = {Subscript[x, 1]'[t] == 0};
eqnvx11 = {Subscript[x, 11]'[t] == 0};

eqnvy = Table[
Subscript[y, i]'[t] == (100*Subscript[y, i][t]), {i, 2, 10} ];
eqnvy1 = {Subscript[y, 1]'[t] == 0};
eqnvy11 = {Subscript[y, 11]'[t] == 0};

s = NDSolve[{eqnvx1 && eqnvx && eqnvx11 && eqnvy1 && eqnvy && eqnvy11,
initialx && initialy}, {Subscript[x, i], Subscript[y, i]}, {t, 0, 
20}]
Plot[Evaluate[Subscript[x, 1][t] /. s], {t, 0, 100}]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

1

your fundamental problem is the variable list:

    ...  {Subscript[x, i], Subscript[y, i]} ..

mathematica does not understand that you meant "for all i", you need to explicitly list:

     NDSolve[ .. ,Flatten[Table[{Subscript[x, i], Subscript[y, i]}, {i, 11}]], {t,0,20} ]

I'm not a fan of using Subscript but it does work in this case.

With that change you get a result.. ( note x1[t] comes out zero, but some others are not all zero )

george2079
  • 38,913
  • 1
  • 43
  • 110
  • thanks @george2079 , this solves my problem :) – Alpha Centaur Dec 01 '15 at 22:11
  • I am normally a MATLAB user, and this is my first exposure to Mathematica ... actually, I am impressed with the subscripts, specially because in newer versions of Mathematica they display like actual subscripts ... – Alpha Centaur Dec 03 '15 at 16:37
  • need your help with one more thing please ... i want to plot (x,y) data for the full range of time ... how can it be done using Table ? thanks ! – Alpha Centaur Dec 08 '15 at 09:02