0
$\begingroup$

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!

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

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.}

$\endgroup$
  • $\begingroup$ I don't know how to thank you, really. Grazie! :) $\endgroup$ – Marco Nov 25 '12 at 11:07

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.