36
$\begingroup$

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.

$\endgroup$
42
$\begingroup$

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]]

Mathematica graphics

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]

Mathematica graphics

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

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ Thank you, it is a very valuable answer. Could you please comment on your function. I could not understand, where from it knows that among all options the Method should be chosen? $\endgroup$ – Alexei Boulbitch Nov 17 '14 at 9:00
  • $\begingroup$ @AlexeiBoulbitch I've added another function to filter only those options which has the Method-> on them and only show those. I kept the original function as is. $\endgroup$ – Nasser Nov 17 '14 at 12:41

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.