# Extract a value from a list of InterpolatingFunction

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!

• Try $u_2$0.5$ \tt{/. lines}$ Nov 24 '12 at 17:25
• The syntax NDSolve[{eqns, initc}, U, {t, 0, T}] might be more useful to you, for starters... Nov 24 '12 at 17:25
• Hint: if you put @Sasha and J.M. advices together you get your answer ;-) Nov 24 '12 at 17:30
• The first several examples in the help documentation for NDSolve show you how. 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}]; Nov 24 '12 at 17:52

A very simple working example:

n = 5;
T = 100;
U[t_] := Table[Subscript[u, i][t], {i, 0, n}];
eqns = Table[Derivative[Subscript[u, i]][t] == 0, {i, 0, n}];
initc = Table[Subscript[u, i] == 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.}

• I don't know how to thank you, really. Grazie! :) Nov 25 '12 at 11:07