Questions tagged [optional-arguments]
Tag for questions about using optional arguments in Mathematica functions.
95
questions
4
votes
1answer
54 views
1
vote
1answer
47 views
How to manually create options that can be entered as a sequence or list?
I am trying to implement custom options in my code manually, rather than using the built-in Options tools. So I have functions that look like ...
2
votes
1answer
40 views
Simplest way to check if optional parameter is omitted?
Suppose I have a function
f[x_,y___]:= (code)
and I want my code to check whether the parameter y is omitted. What's the easiest ...
1
vote
1answer
38 views
How to create custom NIntegrate with special option behavior?
I'm trying to create a custom version of NIntegrate, called MyNIntegrate, with custom option behavior. In particular, I'd like ...
1
vote
0answers
50 views
How to change behavior of Echo or turn it off without removing it from code?
I wish to use Echo for output of intermediate results if an OptionValue I call ...
2
votes
2answers
56 views
Help understanding options on ContourPlot3D
I am creating some figures showing the intersection between two surfaces. I managed to get most of what I want with the following code:
...
0
votes
1answer
71 views
passing splice instructions
Consider some passing splice instructions using start,stop,step pattern
...
0
votes
1answer
54 views
Keep irrelevant variables outside function arguments
I want to define several functions of variables x,y say
...
0
votes
0answers
42 views
Parallelized FactorInteger
FactorInteger has no documented option to be parallelized. Can this be done by some clever hack? Or is there a ready-made substitute that makes use of multiple ...
1
vote
1answer
43 views
Default Options not working in user-defined function for SymbolName
Abstract I have a function objectName[symbol] that returns the SymbolName as both a standalone function or when nested inside ...
3
votes
2answers
65 views
Setting nested optional argument with a default when unpacking from a given Head
I have a head that holds a single argument, and I want to unpack the value inside it while also assigning a symbol to the value itself, for example:
...
1
vote
0answers
43 views
String arguments break optional argument default values? [duplicate]
Following a tip in this post, I use string parameters to label my functions. For example, instead of f[x]:=x^2, I use ...
9
votes
1answer
130 views
Why Optional in Set is not held by the HoldFirst attribute?
When evaluatingf[x_:x0] := x, x0 will be evaluated, regardless of the HoldAll attribute of <...
2
votes
1answer
84 views
Issue using optional argument before options [duplicate]
I have a problem using optional arguments before an OptionsPattern:
...
10
votes
2answers
735 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
87 views
Why is { } interpreted as an option in my function? [closed]
I don't understand the output from:
...
0
votes
0answers
54 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
56 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
35 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 ...
6
votes
0answers
144 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
411 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 ...
1
vote
1answer
900 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
37 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
98 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
50 views
Using other functions' replacement rules
I have a module that uses some default options for NDSolve like so
...
1
vote
1answer
41 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
111 views
Except @ OptionsPattern[] affects OptionValue
The background
This example works as expected, small function with a special case rule:
...
-1
votes
3answers
103 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
159 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
52 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
143 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
55 views
1
vote
0answers
77 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 ...
9
votes
1answer
789 views
2
votes
2answers
322 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
70 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
622 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
105 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
106 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
229 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
78 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 ...
8
votes
2answers
106 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:
...
8
votes
3answers
2k views
6
votes
2answers
506 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
89 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
278 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
38 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:
...
1
vote
1answer
567 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
101 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
107 views
Evaluation of FilterRules inside a Module
I'm trying to customize a plot function according to this code
...