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?
Answer
I think you can actually see (most of) what Mathematica is doing by using Trace[..., TraceInternal -> True]
.
For example,
Select[Flatten[
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)
And
Select[Flatten[
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[#] =!= {}) &]
Comments
Post a Comment