1
$\begingroup$

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}]
$\endgroup$
  • $\begingroup$ what makes you say the code works fine? Lack of error messages does not in itself mean the code is working. It does not work for me with 10.3 on Mac $\endgroup$ – Mike Honeychurch Dec 1 '15 at 21:46
  • 1
    $\begingroup$ Start by Avoiding using subscripted symbols in your code $\endgroup$ – Dr. belisarius Dec 1 '15 at 21:46
  • $\begingroup$ Well, by working fine I meant there are no errors, so I cant know where the problem is. I have to use subscripted symbols otherwise I would need to write 22 equations. $\endgroup$ – Alpha Centaur Dec 1 '15 at 21:50
  • 1
    $\begingroup$ Use, for instance, x[i] instead of Subscript[x, i]. Subscripts work funny in Mathematica. You should follow the link posted by @belisariushassettled and read it. $\endgroup$ – march Dec 1 '15 at 21:55
  • 1
    $\begingroup$ you can use x[1][t] .. $\endgroup$ – george2079 Dec 1 '15 at 21:59
1
$\begingroup$

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 )

$\endgroup$
  • $\begingroup$ thanks @george2079 , this solves my problem :) $\endgroup$ – Alpha Centaur Dec 1 '15 at 22:11
  • $\begingroup$ 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 ... $\endgroup$ – Alpha Centaur Dec 3 '15 at 16:37
  • $\begingroup$ 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 ! $\endgroup$ – Alpha Centaur Dec 8 '15 at 9:02

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.