4
$\begingroup$

Consider simple use of NDSolve[] function used to solve an ODE backward in time

NDSolve[{x'[t] == x[t], x[0] == 1}, x, {t, -1, 0}]

With default settings one can obtain solution in domain $[-1,0]$. If I would like to use a fixed step integration with a priori choosen step size I would call

NDSolve[{x'[t] == x[t], x[0] == 1}, x, {t, -1, 0}, 
 Method -> {"FixedStep", Method -> Automatic, "StepSize" -> 1/10}]

The above code fails to give a result and complains

NDSolve::sss: Unable to determine a starting step size for the method NDSolve`FixedStep. >>

Why is that the "FixedStep" method of NDSolve[] do not support backward in time integration?

$\endgroup$
  • 1
    $\begingroup$ I answered this yesterday... $\endgroup$ – ciao Sep 9 '15 at 21:12
  • $\begingroup$ @ciao Could you please provide a link to the answer? $\endgroup$ – mmal Sep 10 '15 at 7:46
  • $\begingroup$ Oh, sorry, It was leg-pulling, as in I answered it before you posted it, as in... backward in time... $\endgroup$ – ciao Sep 10 '15 at 7:53
3
$\begingroup$

Based on the documentation to "FixedStep" Method for NDSolve, I suggest

s = First@NDSolve[{x'[t] == x[t], x[0] == 1}, x, {t, -1, 0}, 
        StartingStepSize -> 1/10, Method -> {"FixedStep", Method -> Automatic}];
Plot[x[t] /. s, {t, -1, -0}, AxesLabel -> {x, t}]

enter image description here

The key change is to use StartingStepSize as an option instead of "StepSize" as a method.

$\endgroup$
  • $\begingroup$ Yes, I was aware of this solution. But, isn't it a little bit too odd... I mean changing direction of integration shouldn't change the precedence of options? It still doesn't work when one specify both StartingStepSize and StepSize options. $\endgroup$ – mmal Sep 10 '15 at 19:53
  • 1
    $\begingroup$ @mmal. Yes, it is strange. But, there are lots of strange things about Mathematica. $\endgroup$ – bbgodfrey Sep 10 '15 at 20:18
  • $\begingroup$ @mma It doesn't hurt to report it. Who knows if this can be added to the improvements list... $\endgroup$ – P. Fonseca Sep 10 '15 at 21:10
  • $\begingroup$ @mmal I agree. Please do report this. $\endgroup$ – bbgodfrey Sep 10 '15 at 21:30
  • $\begingroup$ @P.Fonseca I think it does not. The purpose of this question was to see if anyone has a working solution, probably someone may know more about the NDSolve machinery and be able to explain observed behavior... $\endgroup$ – mmal Sep 11 '15 at 6:55

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.