Why is NDSolve's StartingStepSize with ExplicitEuler not working? How do I set the step size?

Why do I get a smooth curve (that is obviously wrong) when I run this?

Plot[
Evaluate[
NDSolveValue[{x'[t] == -x[t], x[0] == 1}, {x[t]}, {t, 0, 1},
StartingStepSize -> 1, Method -> {"FixedStep", Method -> "ExplicitEuler"}]],
{t, 0, 1},
PlotRange -> All]


Shouldn't I just get back a straight line connecting (0, 1) to (1, 0)?!

How do I make Mathematica just do a plain classic Forward Euler?! I don't want fancy smoothing...

-

You have to set MaxStepFraction, too, say, to 1.

Plot[
Evaluate[
NDSolveValue[{x'[t] == -x[t], x[0] == 1}, {x[t]}, {t, 0, 1},
StartingStepSize -> 1, Method -> {"FixedStep", Method -> "ExplicitEuler"},
MaxStepFraction -> 1]],
{t, 0, 1},
PlotRange -> All]


It's not a straight line because the value of the derivatives are stored & used in the InterpolatingFunction solution. However, we can see there are only two points.

sol /. t -> "Grid"
(*  {{{0.}, {1.}}}  *)

-
+1 Ahhh! Is there any way to make it draw without smoothing then? It's so misleading the way it draws it... – Mehrdad Feb 15 at 2:41
@Mehrdad Oops, made a mistake editing the comment. Try sol1 = Interpolation[Table[{t, sol}, {t, Flatten[sol /. t -> "Grid"]}], InterpolationOrder -> 1]. – Michael E2 Feb 15 at 2:57
Awesome, got it! It ended up being sol = Evaluate[ NDSolveValue[{x'[t] == -x[t], x[0] == 1}, x[t], {t, 0, 1}, StartingStepSize -> 1, MaxStepFraction -> 1, Method -> {"FixedStep", Method -> "ExplicitEuler"}]]; sol = Interpolation[Table[{t, sol}, {t, Flatten[sol /. t -> "Grid"]}], InterpolationOrder -> 1][t]; Plot[sol, {t, 0, 1}, PlotRange -> All]. – Mehrdad Feb 15 at 3:03
PS, this might be more painful but for future reference it might be nice to add how to do it if we're solving for multiple values (e.g. {x[t], x'[t]}). – Mehrdad Feb 15 at 3:06
@Mehrdad I'm not sure what you mean, actually. But, one can plot a linear interpolation with ListLinePlot[sol = NDSolveValue[{x'[t] == -x[t], x[0] == 1}, x, {t, 0, 1}, StartingStepSize -> 1, Method -> {"FixedStep", Method -> "ExplicitEuler"}, MaxStepFraction -> 1]], even though sol is still order 3. ListPlot and ListLinePlot show only the steps, or interpolated points, in an InterpolatingFunction. – Michael E2 Feb 15 at 3:30

I would suggest (as an alternative) the following

pointsAndValues[x_InterpolatingFunction] :=
Transpose[{First[x["Coordinates"]], x["ValuesOnGrid"]}];

ListPlot[
pointsAndValues@
First@NDSolveValue[{x'[t] == -x[t], x[0] == 1}, {x}, {t, 0, 3},
StartingStepSize -> 1,
Method -> {"FixedStep", Method -> "ExplicitEuler"},
MaxStepFraction -> 1], Joined -> True, PlotMarkers -> Automatic]


And to check the convergence use e.g.

ListPlot[pointsAndValues@
First@NDSolveValue[{x'[t] == -x[t], x[0] == 1}, {x}, {t, 0, 2},
StartingStepSize -> 1/#,
Method -> {"FixedStep", Method -> "ExplicitEuler"},
MaxStepFraction -> 1] & /@ {1, 2, 4, 16}, Joined -> True,
PlotMarkers -> Automatic]

-