Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

By running the code

n = 5;
U[t_] := Table[Subscript[u, i][t], {i, 0, n}];
lines = NDSolve[{eqns, initc}, U[t], {t, 0, T}]

I get the output

{{u_0[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t], 
  u_1[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t],
  u_2[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t], 
  u_3[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t], 
  u_4[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t], 
  u_5[t]->InterpolatingFunction[{{0.`,5.`}},"<>"][t]}}

(it's the solution of a system of ODEs that I obtain by discretizing a PDE with the method of lines). Now I would like to extract a particular value for each function, for example u_2[0.5] but I'm not managing to do that. Can someone help me?

Thank you so much!

share|improve this question
    
Try $u_2\[0.5\] \tt{/. lines}$ –  Sasha Nov 24 '12 at 17:25
    
The syntax NDSolve[{eqns, initc}, U, {t, 0, T}] might be more useful to you, for starters... –  J. M. Nov 24 '12 at 17:25
    
Hint: if you put @Sasha and J.M. advices together you get your answer ;-) –  chris Nov 24 '12 at 17:30
2  
The first several examples in the help documentation for NDSolve show you how. –  JohnD Nov 24 '12 at 17:45
    
Thank you everyone, but it's still not working. Maybe it is because I actually initialized the function U[t] in the beginning as U[t_] := Table[Subscript[u, i][t], {i, 0, n}]; –  Marco Nov 24 '12 at 17:52

1 Answer 1

up vote 1 down vote accepted

A very simple working example:

n = 5;
T = 100;
U[t_] := Table[Subscript[u, i][t], {i, 0, n}];
eqns = Table[Derivative[1][Subscript[u, i]][t] == 0, {i, 0, n}];
initc = Table[Subscript[u, i][0] == 1, {i, 0, n}];
lines = NDSolve[{eqns, initc}, U[t], {t, 0, T}];

U[t] /. First@lines /. (t -> .5)

{1., 1., 1., 1., 1., 1.}

Alternatively:

vars = Table[Subscript[u, i], {i, 0, n}]
sol = NDSolve[{eqns, initc}, vars, {t, 0, T}]
#[t] & /@ vars /. First@lines /. (t -> .5)

{1., 1., 1., 1., 1., 1.}

share|improve this answer
    
I don't know how to thank you, really. Grazie! :) –  Marco Nov 25 '12 at 11:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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