Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [optional-arguments]

Tag for questions about using optional arguments in Mathematica functions.

10
votes
2answers
713 views

Define function that behaves almost identically to Mathematica function

Often I like to define my own functions that are almost exactly the same as Mathematica defined functions, apart from a few tweaks. See this question for example. I want to define them properly so ...
5
votes
1answer
77 views
0
votes
0answers
41 views

Optional argument in Set Function [duplicate]

Optional arguments can be defined in SetDelayed (:=) Functions (see f1 below and here and here). However, how can one accomplish this in Set (=) Functions (see f2 and f3 below)? ...
2
votes
1answer
44 views

OptionValue and OptionPattern not Changing Values

I am trying to produce a function with a few sets of arguments, one of which can accept options. However it doesn't seem to be responding to the changes that I accept. ...
0
votes
0answers
23 views

Method option of function MatrixRank

By running ??MatrixRank, I see that it has an optional argument named Method. However, this argument is not in the ...
5
votes
0answers
69 views

OptionsPattern[] Vs. opt___ [closed]

Since version 6 I've been dutifully using OptionsPattern[] instead of the original opts___ for passing options to functions. I ...
8
votes
2answers
385 views

Are Mathematica commands always supposed to check that Method -> name is valid?

When calling a Mathematica command which accepts a Method -> name option, I always thought that if the name given is not a ...
0
votes
1answer
202 views

Set absolute size of Axis or frame for a plot

I have to publish some work and it requires to meet specific criteria for the image size and plot size. 1) the Area of the figure must be fix 2) the width of the x-axis also must be fix for any plot ...
2
votes
0answers
30 views

Scoping of OptionValue for inner functions in closures

Assume a function f is a closure over an inner function g. Both f and ...
4
votes
2answers
82 views

How to prevent an Optional parameter from taking an OptionsPattern parameter without multiple function definitions? [duplicate]

I have function the needs to enable some Optional parameters and an OptionsPattern. The issue I am facing is that the options ...
3
votes
1answer
47 views

Using other functions' replacement rules

I have a module that uses some default options for NDSolve like so ...
1
vote
1answer
38 views

Why doesn't OptionValue cooperate with Map? [duplicate]

Consider the following definition: Options[f] = {a -> 1, b -> 2} f[x_,OptionsPattern[]] := {x,OptionValue/@{a,b}} I thought that doing something like ...
9
votes
1answer
99 views

Except @ OptionsPattern[] affects OptionValue

The background This example works as expected, small function with a special case rule: ...
-1
votes
3answers
77 views

OptionsPattern Confusion

I want to use the whole options pattern as the argument for HTTPRequest's "Query" parameter, but I'm not sure how to use them. When I run the following code: ...
5
votes
1answer
137 views

What is the difference between the second argument of ToString and its option FormatType?

Is there any real difference between ToString[expr, form] and ToString[expr, FormatType→form]? In all my examples, they seem to ...
1
vote
0answers
45 views

What is the best way to pass on options? [duplicate]

Say I have two functions which take the same set of options, e.g. Options[f1] = {a -> 1}; Options[f2] = {a -> 1}; Now, ...
4
votes
2answers
136 views

How to define an option or an argument whose values are confined

I want to define a function whose arguments or options can only be selected in a range. For example: ...
5
votes
0answers
52 views

Optional in MatchQ [duplicate]

Why isn't the first one True in: ...
1
vote
0answers
47 views

Automatic is not always the default option

Contrary to what one might expect, specifying an option to be Automatic sometimes changes the output. For example, by default ...
8
votes
1answer
480 views

define a function with optional arguments

I have defined a function as follows: ...
2
votes
2answers
168 views

Anonymous Function And Optional Arguments [duplicate]

Is there a way to get an optional arguments to work in an anonymous function. Function[{Optional@a},If[a,True,False]]
3
votes
2answers
61 views

How to define a function with an optional value related to the arguments?

It's known that we can easily define a function with optional value which is not related with other arguments, but my question is how can I define a function with an optional value which is really ...
12
votes
4answers
595 views

Optional argument that can be completely omitted?

I am writing a simple function return similar words. Clear[similarWords] similarWords[string_]:=Nearest[WordList[],string] I want to add another argument ...
6
votes
0answers
94 views

Examples of the single dot form of Optional?

I've known of the single dot form of Optional for a while, but never had occasion to actually use it: Are there any good examples of use cases for it other than in relation to ...
2
votes
0answers
105 views

How to create a function with option that shows dropdownlist like ( for example ) Manipulate with ControlPlacement? [duplicate]

Consider the Mathematica function Manipulate where you assign the placement of the controls with the option parameter ...
14
votes
1answer
204 views

Pattern matching with List and Optional

Bug introduced in 8.0.4 or earlier and persists through 11.1.1 Thank you for bringing this to our attention. I have filed a report with our developers. Why does this ...
2
votes
1answer
66 views

Is this the correct method for using optional arguments?

I've read this page but I'm still kind of confused about something. Here's a simple example function, where it simply plots a function. If you give it the ImageSize option, it should use that, but ...
6
votes
2answers
92 views

How to write a `HeldOptional` variant of `Optional` that does not evaluate its second argument?

How to specify optional arguments that take functional values made me wonder: Can we come up with a variant of Optional that allows to do the following: ...
5
votes
3answers
487 views

Functions with both optional arguments and options [duplicate]

I have the following codes: ...
6
votes
2answers
399 views

How to make a customized plot function that can plot functions with optional parameter?

Suppose I make the following function to plot contour lines for a complex function: ...
3
votes
1answer
82 views

How to speed up accidental large output?

From time to time I accidentally let large expressions like RandomReal[1., {10^5, 10, 10}] reach the front end. The computation of the result is quite fast (...
9
votes
1answer
202 views

Why is this syntax for patterns with Optional values not supported?

I want to express Optional[PatternTest[Pattern[a,Blank[]],t],1] concisely. a : _?t : 1 is not quite this but works: ...
0
votes
0answers
37 views

How to use OptionValue inside a pure function [duplicate]

I want to define a function with OptionsPattern as argument which returns a pure function using OptionValue: ...
0
votes
1answer
387 views

How to pass arguments in NIntegrate and NDSolve

I am solving PDEs with NDSolve and NIntegrate, but I do not know how to pass arguments correctly. My orignial code is very ...
1
vote
1answer
87 views

User-defined density plotting function with a functional argument: extracting variables from the function and plotting in a circular region

I would like to customize the function DensityPlot and use it in a package as a function called MyDensityPlot: The functions ...
2
votes
1answer
89 views

Evaluation of FilterRules inside a Module

I'm trying to customize a plot function according to this code ...
2
votes
1answer
108 views
26
votes
2answers
459 views

Version inconsistency with optional arguments: what if the default value doesn't match the pattern?

I just came across some weird behaviour. Take this function definition: ClearAll[f] f[vs_List : All] := "match" The default value of ...
5
votes
1answer
101 views

An unexpected match when using Condition, Optional and passing a Sequence

Mathematica is behaving in an expected way when passing a parameter with an Optional and a Sequence. Here is an example: ...
8
votes
3answers
91 views

How to add Optional Sequence

Note: This question could be duplicate but I couldn't find any so far. It is know that Optional (:) can be use to represent expression if omitted. ...
12
votes
2answers
230 views

Optional throws error when called from a package. Workaround?

Bug introduced in 8.0 or earlier and fixed in 11.0.0 Case number: 305932. In the front-end notebook (Mathematica 9.0 and 10.2): g[x: Optional[_,default]]:=x; ...
5
votes
1answer
112 views

SyntaxInformation and Options

I wonder if the following behaviour of SyntaxInformation is a bug: I want a function f to accept one argument and options, so I ...
7
votes
2answers
244 views

Option inheritance: setting new defaults and private context

I'm having issues with inherited options for functions I defined in a package file. Setting new default options doesn't quite work as I expect. Also, a function which I'd like to stay private to the ...
2
votes
1answer
65 views

Determining Automatic Parameters used by Mathematica [duplicate]

When you use plotting functions like ContourPlot3D, there are lots of parameters that are left as Automatic if you do not ...
17
votes
4answers
533 views

Skipping “middle” Optional Arguments

Is there a way to call a function where the "middle" arguments should use their default value while specifying values for the "right-most" arguments? For example, given this function: ...
2
votes
0answers
73 views

Documentation on the attribute OneIdentity [duplicate]

The documentation on the attribute OneIdentity says OneIdentity is an attribute that can be assigned to a symbol f to ...
2
votes
2answers
127 views

Plot does not take range with OptionValue and PlotRange option

I am making a function that is to use Show to overlay a few plots of a function. I want the first Plot in ...
15
votes
1answer
348 views

Confused by the opts : OptionsPattern[ ] pattern

I'm trying to make sense of the syntax in the clause opts:OptionsPattern[], as found in this standard "rule-based" (pseudo-)function definition pattern: ...
7
votes
2answers
360 views

Optional arguments with lists as function parameter

I'm developing a function f which should support optional arguments {x_, y_} in list form. A simple example looks like this: <...
2
votes
1answer
118 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...