# Plotting with NDSolveStateData

This question is a continuation of this.

As answered by J.M., I am able to iterate a solution. However, I am unable to plot it. I am sure that this has to do with my inability to understand how the plot routine works and I can't seem to figure it out:

state = First[
NDSolveProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x],
u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, t, {x, 0, 5}]]

NDSolveIterate[state, 5]
NDSolveProcessSolutions[state, "Forward"]

Plot3D[
Evaluate[u[t, x] /. NDSolveProcessSolutions[state, "Forward"]],
{t,0,2},
{x, 0, 5}
]


gives me a blank plot with no curves. What am I doing wrong? I can't omit {t, 0, 2} as that would give me an error.

• have a look at this: reference.wolfram.com/mathematica/tutorial/… – acl May 22 '12 at 15:23
• @acl I did have a look at that. When I replaced the u[t,x,y] equation with u[t,x], all I got was blank plots. – dearN May 22 '12 at 15:24

## 2 Answers

If you look at the interpolation object that's returned, it's not a function u(t,x) only u(x) with fixed t. In fact, it returns both u[x] and u'[x] for fixed t. So try

state = First[
NDSolveProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x],
u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, t, {x, 0, 5}]]

Table[NDSolveIterate[state, t];
Plot[NDSolveProcessSolutions[state, "Forward"][[All, 2]], {x, 0, 5},
PlotRange -> 1], {t, 0, 5}] • Thanks for making the distinction between u[t,x] and u[x]. It wasn't obvious to me! :) – dearN May 23 '12 at 14:35

Something like this?

L = -10;
state = First[
NDSolveProcessEquations[{D[u[t, x],
t] == + D[u[t, x], x, x] - Sin[u[t, x]],
u[0, x] == Exp[-(x^2)],
u[t, -L] == u[t, L]}, u, t, {x, -L, L},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}]];
GraphicsGrid[Partition[Table[
NDSolveIterate[state, tau ];

Plot[Evaluate[
u[tau, x] /.
NDSolveProcessSolutions[state, "Forward"]], {x, -L, L},
PlotRange -> {-1/4, 1/4}],
{tau, 0., 3., .5}], 2]] • You know, I'll have to check my [ and see if all is well with my code. – dearN May 22 '12 at 15:49