Tag for questions about using optional arguments in Mathematica functions.

learn more… | top users | synonyms

48
votes
6answers
3k views

How can I create a function with optional arguments and options?

Is it possible to create a function with optional arguments that also takes options? Here is a simple example. I have a function f with option "g". It also has ...
27
votes
5answers
837 views

Can I make a default for an optional argument the value of another argument?

I'd like to define a function with several optional arguments, some of which default to the value supplied for other arguments. For example, I'd like to be able to write something like ...
25
votes
2answers
1k views

Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
20
votes
1answer
1k views

How to Combine Pattern Constraints and Default Values for Function Arguments

EDIT: As several respondents have noted in the answers and comments below, the original example had a default value that would never be used because of the way patterns and default values are ...
19
votes
1answer
258 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 ...
15
votes
4answers
424 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: ...
14
votes
1answer
137 views

Unexpected pattern matching behaviour: PatternSequence vs. Optional

fixed in 10.1 (windows) Consider the following pattern-matching expressions: ...
13
votes
4answers
648 views

How to make a function with its own options as well as passing options to other functions [duplicate]

I have a function with many of its own options, but I would also like to pass options to subfunctions using the FilterRules function. Here's a simple example: ...
13
votes
2answers
377 views

How to speed up the plotting of B-spline curve?

Three months ago, I asked a quesion about B-Spline basis function here, Today, I used this function to plot B-spline curve. The definition of $N_{i,p}$ ...
12
votes
2answers
661 views

How to test if optional argument has been given?

I understand that the last call (f[1]) returns True because arg does not exist and thus ...
12
votes
1answer
379 views

Is it possible to use Compile on a function with optional arguments?

My Mathematica is a little rusty, so apologies in advance. I think my problem is quite simple, but I can't seem to find the answer on my own! Simple example : ...
11
votes
2answers
191 views

Optional throws error when called from a package. Workaround?

Bug introduced in 8.0 or earlier and persisting through 10.3 or later. Case number: 305932. In the front-end notebook (Mathematica 9.0 and 10.2): ...
11
votes
2answers
288 views

How do I override options with my own defaults?

I'm calling a function f from within a function g and would like to pass any valid options for ...
10
votes
4answers
249 views

Is it possible to separately call the default value of a variable which isn't at the end of the sequence?

After reading this post I recalled an old question I once met. We know that we can set default values for variables of a function: ...
9
votes
0answers
142 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: ...
8
votes
1answer
1k views

Which methods are available for NMinimize?

I can't find in the documentation the list of methods available to NMinimize[]. Is there a way to get this? The NMinimize page in Documentation Center mentions only ...
7
votes
2answers
259 views

Is it possible to use PatternTest and Optional value on one Pattern simultaneously? [duplicate]

Possible Duplicate: How to Combine Pattern Constraints and Default Values for Function Arguments First a simple example: define a function "add" with two arguments, and its second argument ...
7
votes
2answers
135 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 ...
7
votes
1answer
178 views

Specifying optional arguments with variables

Perhaps this is poor programming on my part, but I would like to create a function that uses a variable as an optional parameter: var = 2; f[a_:var] := {a} The ...
7
votes
2answers
159 views

Change some option of a function when calling it [duplicate]

Say I have defined some function like f[p_] := Plot[Sin[p*x], {x, 0, 2 Pi}] Now in most cases, I just need to specify the value of ...
6
votes
2answers
148 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: ...
6
votes
1answer
207 views

How to find the options available for a function? [duplicate]

I was trying to create an animated .gif with Mathematica. I knew that the function to use was Export["animation.gif",tableplot] where ...
6
votes
1answer
115 views

A question about two ways to use Default

Usually we define a function with default values by the syntax x_:default, but there is another technique to do this by registering a global default value with ...
5
votes
1answer
81 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: ...
5
votes
1answer
119 views

Add options to upvalues

I have some objects that I want to present in TeXForm. Thus, it is easily to do as follows: YoungTableau/:TeXForm[YoungTableau[diagram_]] However, what if I ...
5
votes
1answer
47 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 ...
4
votes
2answers
184 views

How to use Optional as an omissible parameter in pattern-match?

Below is a function intended to test if an expression is a polynomial in which all the coefficients and exponents are integers: ...
4
votes
1answer
653 views

Evaluating function only when its optional argument is numeric

I want to have the argument 'a' for myf2 in form of optional argument, but at the same time I need to evaluate the function only if 'a' is Numeric, see also my previous question. ...
4
votes
2answers
118 views

How do I make my function behave more like Plot? [duplicate]

I have written a function Fun as below: ...
3
votes
3answers
367 views

Plot graphs with direction and numbered in Mathematica

I would like to write a code in Mathematica such that it shows the direction with numbers on points. I wrote this code which does not do this. I want just to complete this code with two options I ...
3
votes
2answers
47 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. ...
3
votes
2answers
157 views

How to deal with the condition that a function own many options?

Assming that I have a function myFunc which has some options. ...
3
votes
1answer
138 views

How can I define a function taking two distinguishable sets of options?

It commonly happens that one wants to define some function foo which in turn calls some other function (e.g., Plot) that can ...
3
votes
0answers
87 views

Function of arguments given in non-fixed order [duplicate]

normally we define functions as f[x_, y_, z_] := ArcSin[x^2*y/z] however when one has many arguments (as I do) I find difficult to remember what is the meaning ...
2
votes
2answers
74 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 ...
2
votes
1answer
56 views

Evaluation of FilterRules inside a Module

I'm trying to customize a plot function according to this code ...
2
votes
1answer
74 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. ...
2
votes
1answer
103 views

How to specify optional arguments that take functional values

I am trying to make a function with an optional argument that may change but mathematica caches the value when the function is defined. Here is an example where the optional time variable is set when ...
2
votes
1answer
50 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 ...
2
votes
0answers
57 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
0answers
95 views

How can this function's options be used in different places? [duplicate]

I wrote this function to make a ListPlot where the points are colored by a third argument. ...
1
vote
1answer
57 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 ...
0
votes
3answers
420 views

How to combine multiple functions into a single function, indexed bya new argument

I have a system of expressions (matrices) which correspond to increasing orders of precision in a theory. These expressions are quite complex (require about 40+ lines of code to produce) and are not ...
0
votes
2answers
1k views
0
votes
0answers
34 views

Use Map with OptionValue [duplicate]

Trying to map OptionValue to a list of option names doesn't work. ...
0
votes
1answer
132 views

How to make an index optional?

Can I define a relation between variables, such that the expression will also be evaluated (then assuming all indices are equal) when no index is given? $$ x_i + y_j = \delta_{ij} ...