# Starting NDSolve from intermediate time step?

I always wondered if I could start NDSolve from an intermediate time step.

What I mean is, in the code sample below, if I were to run my solution from tmin=0 to tmax=2 and then I realize that my solution hasn't converged yet, could I just change my tmin to 2 and then proceed with a larger tmax (in this case the solution coverges [attains steady state in this example] at tmax=5).

This is because very often I solve 4th order Nonlinear PDEs with NDSolve, some of which take over 70-80 minutes to complete (as I run them for long times of a million time steps or so) and then I realize that the solution hasn't converged yet. So can I just, as in my presumed working example, change my tmin to my tmax from the previous run and change my tmax to a larger run?

tmin = 0;
tmax = 5;
sol = NDSolve[{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, tmin, tmax}, {x, 0, 5}];
Plot3D[Evaluate[u[t, x] /. sol], {t, tmin, tmax}, {x, 0, 5},
PlotRange -> All]

• By "converged" you mean "reached a steady state"? Regardless, you might use the old solution to give initial and boundary values for starting anew. Commented May 14, 2012 at 23:31
• @DanielLichtblau Yes, steady state. Commented May 15, 2012 at 0:25

You could integrate up to some intermediate time, tintermediate, and then feed the result as initial conditions to the solver to propagate from tintermediate to tmax, like so:

tmin = 0;
tintermediate = 2;
tmax = 5;
sol = NDSolve[{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, tmin, tintermediate}, {x, 0, 5}];
sol2 = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x],
u[tintermediate, x] \[Equal] First@(u[tintermediate, x] /. sol),
u[t, 0] == Sin[t], u[t, 5] == 0},
u, {t, tintermediate, tmax}, {x, 0, 5}];

• Thanks! Just so that I understand this right sol2 is the solution from t=2 to t=5...? Commented May 15, 2012 at 0:31
• Yes, that is what it is
– acl
Commented May 15, 2012 at 0:32
• Ok. Thanks! I actually just learned the use of @! Commented May 15, 2012 at 0:36
• ah yes. glad to be of help!
– acl
Commented May 15, 2012 at 0:45

As it turns out, the designers of NDSolve[] have precisely anticipated this sort of use; this is where you can use the NDSolveStateData framework.

To use acl's example:

(* prepare PDE *)
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}]];

(* go up to t = 2 *)
NDSolveIterate[state, {0, 2}]
NDSolveProcessSolutions[state, "Forward"]

(* go up to t = 5 *)
NDSolveIterate[state, 5];
NDSolveProcessSolutions[state, "Forward"]


See the docs for more details.

• good point, +1!
– acl
Commented May 15, 2012 at 0:46
• Awesome! I'll look into the documentation. This is quite nifty! (Not taking anything away from the previous answerer :)) Commented May 15, 2012 at 12:16
• Why am I not able to plot the solution u[t,x] with Plot3D[ Evaluate[u[t, x]], {t, 2, 5}, {x, 0, 5} ] OR Plot3D[ u[t, x]/.sol, {t, 2, 5}, {x, 0, 5} ] where sol= NDSolveProcessSolutions[state, "Forward"] ` Commented May 22, 2012 at 14:33