Mathematica 9 is now available
 Documentation / Mathematica / Add-ons / Standard Packages / Utilities  /

Utilities`FilterOptions`

The function FilterOptions is used to select valid options when passing options from one function to another.


A utility function for passing options.

As an application of FilterOptions, consider writing a new function PlotIntegrate that calls the functions Plot and NIntegrate and plots the numerical integral of a function. Although the function PlotIntegrate does not use options directly, it passes options along to Plot and NIntegrate. Options that are valid for NIntegrate, however, are not valid for Plot, and options that are valid for Plot are not valid for NIntegrate. The function FilterOptions is used to select a valid set of options for each function.

  • This loads the package.
  • In[1]:= << Utilities`FilterOptions`

  • Here is a simple program that uses the FilterOptions function. Valid options are selected using FilterOptions before passing the option sequence to Plot or NIntegrate.
  • In[2]:= PlotIntegrate[f_, {x_, a_, b_}, opts___] :=
    With[{
    optPlot = FilterOptions[Plot, opts],
    optNInt = FilterOptions[NIntegrate,
    opts]},
    Plot[
    NIntegrate[f, {x, a, t}, optNInt],
    {t, a, b}, optPlot] ]

  • In this example, the Frame->True and GridLines->Automatic options are passed to Plot but not to NIntegrate. An error would occur if these options were passed to both functions.
  • In[3]:= PlotIntegrate[Sin[x], {x, 0, 3},
    Frame -> True, GridLines -> Automatic]




    Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information

    THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
    SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.