Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are commands like NonlinearModelFit[] or NDSolve[] that have the option Method it typically defaults to Automatic. How can you check after the evaluation of the command which method Mathematica picked?

share|improve this question
Some functions have their defaults indicated in the manual. As an example, for solving (systems of) ODEs with NDSolve[], by default it switches between "BDF" and "Adams", depending on whether the system being solved is stiff or not. If you're performing nonlinear least squares with FindFit[], Mathematica is smart enough to automatically use "LevenbergMarquardt". – J. M. Jan 18 '12 at 11:30
Of course, that is what Mathematics does. But how do I check? I can use Options to check which ones were given. But there is no such thing like Method[%] that informs me what Mathematics did. If I publish results I cannot write "The fitting was probably done with LevenbergMarquardt, but I can’t tell for sure, because there is no command to check." – uli Jan 18 '12 at 11:34
This mentions some of the defaults taken. – J. M. Jan 18 '12 at 11:34
"If I publish results I cannot write..." - ergo, you should try to specify options explicitly if you want everything to be transparent. – J. M. Jan 18 '12 at 11:36
" it decidable whether a system is stiff or not?" - it's not entirely foolproof, but Mathematica does have stiffness detection methods. See this and this for instance. – J. M. Jan 18 '12 at 12:00
up vote 31 down vote accepted

I think you can actually see (most of) what Mathematica is doing by using Trace[..., TraceInternal -> True].

For example,

  Trace[NDSolve[y'[x] == x && y[0] == 0, y, {x, 0, 6}], 
   TraceInternal -> True]], ! FreeQ[#, Method | NDSolve`MethodData] &]

shows the DE was evaluated using NDSolve`LSODA and Newton's method. (I think)


  Trace[NDSolve[{Derivative[1][x][t]^2 + x[t]^2 == 1, x[0] == 1/2}, 
    x, {t, 0, 10 Pi}, SolveDelayed -> True], 
   TraceInternal -> True]], ! FreeQ[#, Method | NDSolve`MethodData] &]

used NDSolve`IDA.

As an aside, here's something I just learnt from Trott's Mathematica guidebook for numerics, to see all of the methods and suboptions for NDSolve

{#, First /@ #2} & @@@ 
 Select[{#, Options[#]} & /@ (ToExpression /@ 
   DeleteCases[Names["NDSolve`*"],(* PDE method only *) "NDSolve`MethodOfLines"]), 
   (Last[#] =!= {}) &]
share|improve this answer
I just saw ruebenko's answer. Using TraceInternal as above seems to give the same list of methods as his data, but it requires a lot of digging... – Simon Jan 18 '12 at 12:04

For NDSolve with one step methods you can use the MethodMonitor.

data = Last[
   Reap[sol = 
      NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30},
        Method -> "StiffnessSwitching", 
       "MethodMonitor" :> (Sow[NDSolve`Self[[0]]];)];]];



Adams, BDF, IDA are multi-step methods and do not work with this approach.

share|improve this answer
Nice! But if I am not mistaken, this seems to be a NDSolve[] only solution? – uli Jan 18 '12 at 12:07
@Uli , sorry only got this question now, yes, this is NDSolve specific. – user21 Mar 19 '12 at 9:34

I asked this question once after a presentation by Jon McLoone. His answer was that that was not possible and that Mathematica can switch methods many times if the situation asks for it. So it wouldn't be useful either. I agree that this is not completely satisfactory.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.