The option Methodapplies for several functions, such as NDSolve, FindRoot, NIntegrate and some others. It is difficult, however, to find a list of Methods for a given function. By digging through tutorials I extracted, for example, a list of Methods for NIntegrate:
"GlobalAdaptive"
"ClenshawCurtisRule"
"NewtonCotesRule",
"GaussKronrodRule",
"ClenshawCurtisRule"
"MultidimensionalRule"
"GaussKronrodRule",
"LobattoKronrodRule"
"SingularityHandler"
"DuffyCoordinates"
"Trapezoidal"
"AdaptiveMonteCarlo"
BDoubleExponentialOscillatory
MultiPeriodic,
MonteCarlo,
QuasiMonteCarlo,
AdaptiveQuasiMonteCarlo
ExtrapolatingOscillatory,
MultiPeriodicDoubleExponentialOscillator,
DoubleExponentialOscillatory
though I am not sure that my collection is complete.
Is there a way to get a complete list of Methods for a given function? I mean not only NIntegratebut also others.
Answer
I use this function
getList[name_String] := Module[{options, idx}, options = Names[name <> "`*"];
options = ToExpression /@ options;
options = {#, Options[#]} & /@ options;
idx = Range[Length[options]];
options = {#[[1]], TableForm[#[[2]]]} & /@ options;
options = Insert[options[[#]], #, 1] & /@ idx;
options = Insert[options, {"#", "Option", "Options to this option"}, 1]
];
To use:
r = getList["NIntegrate"];
Grid[r, Frame -> All, Alignment -> Left, FrameStyle -> Directive[Thickness[.005],
Gray]]

I modified the above a bit based on function I think I got from one of the Mathematica Guide books but I do not remember now which book it was. The methods can be seen under the third column there by looking for Method-> there. At least this is much easier than having to scan pages and pages of help looking for these things.
Replace the name of the command above to get other functions. To filter the Method-> part automatically, one possible way would be to use Cases or some pattern on the result r above. This is left as an exercise for the pattern experts out there.
Update Response to comment below. I made new version called getList2 which only shows up the options with Method on them. I am sure this could be written better, but I am not good with patterns. Here we go
getList2[name_String] := Module[{options, idx,z1,z2},
options = Names[name <> "`*"];
options = ToExpression /@ options;
options = Flatten[Last@Reap@Do[z1 = Options[options[[i]]];
If[z1 != {},
z2 = Cases[z1, Rule["Method", x_] :> Method -> x];
If[Length[z2] != 0 , Sow[{options[[i]], z2}]]
],
{i, Length[options]}
], 1];
(* rest for formatting*)
idx = Range[Length[options]];
options = {#[[1]], TableForm[#[[2]]]} & /@ options;
options = Insert[options[[#]], #, 1] & /@ idx;
options = Insert[options, {"#", "Option", "Options to this option"}, 1]];
Example calls
r = getList2["NIntegrate"];
Grid[r, Frame -> All, Alignment -> Left]

r = getList2["NDSolve"];
Grid[r, Frame -> All, Alignment -> Left]

Comments
Post a Comment