I'm numerically solving a PDE (time+1D space) with NDSolve
and want to plot some spatial profiles. Plot
works, but is very slow compared to ListPlot
. Here's an example (Fisher-KPP equation):
l = 100;
tmax = 30;
pts = 1000;
sol = NDSolve[{
D[n[x, t], t] == n[x, t] (1 - n[x, t]) + D[n[x, t], {x, 2}],
n[x, 0] == If[45 < x < 55, 1, 0], n[0, t] == n[l, t]}, {n}, {t, 0, tmax}, {x, 0, l},
Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> pts}}
][[1]];
First@Timing[Plot[Evaluate[n[x, 15] /. sol], {x, 0, l}]]
(* 13.0701 *)
First@Timing[ListLinePlot[Table[{x, n[x, 15] /. sol}, {x, 0, l}]]]
(* 0.064737 *)
Can Plot
be sped up? Maybe there is a nice way to extract a 1D InterpolatingFunction slice from a 2D InterpolatingFunction?
FunctionInterpolation[]
is usable for slicing. $\endgroup$